Last Thursday I passed the 70-541 MCTS: Microsoft Windows SharePoint Services 3.0: Application Development exam. So now I officially should know something about SharePoint development.

I have been advertising Ruby and IronRuby at my company for a while now — or trying too. We are a .NET solution provider and sofar they’re not convinced that Ruby will be worth the effort of learning. Oh well. One of these days I will come up with the decisive argument.

Thinking of that, maybe you can help out. What arguments would you use to have your company at least put some serious effort into exploring Ruby and/or IronRuby?

For completeness’ sake, IronRuby is Microsoft’s .NET implementation of the Ruby language. This means that we get all the dynamic language goodness of Ruby combined with the full range of .NET libraries available to C# (and any other .NET language) developers.

Justin Etheredge of CodeThinked has put together a set of tutorials geared specifically to help C# developers get up to speed with IronRuby quickly. If these don’t bring a great number of C# programmers to start experimenting with Ruby I don’t know what will.

The first two tutorials take you through setting up IronRuby and running a simple application:

And then the fun begins:

Justin is very actively adding new tutorials to the above list. The full series can be found here. I definately suggest subcribing to the RSS feed to keep updated.

It took a while, but the DevDays 2008 presentations are finally online. You can find them here:

DevDays 2008 Powerpoints

I ran into a situation a while ago that I needed to retrieve a serialized object from the database, copy its properties to another object and send that object over the wire. Why the copying? The object stored in the database were written in .NET 2.0, whereas the service I was sending the object to expected .NET 3.5 (WCF) objects.

It was also perfectly possible that the .NET 3.5 objects, which were being developed by another team, would have had properties added or removed without notification.

The following code allows you to copy property values from one object into another. If a property does not exist in the target object, it is ignored. I ran into some issues with indexed properties (aka lists and arrays) which do not allow you to copy the properties of their contained items. So I do some additional reflection magic there to build the array or list dynamically.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Private Function CopyProperties(Of sourceType As {Class, New}, targetType As {Class, New})(ByVal source As sourceType, ByVal target As targetType) As targetType
  Dim retValue As New targetType
 
  Dim sourceProperties() As PropertyInfo = source.GetType().GetProperties()
  Dim targetProperties() As PropertyInfo = GetType(targetType).GetProperties()
 
  For Each sourceProp As PropertyInfo In sourceProperties
    For Each targetProp As PropertyInfo In targetProperties
      If sourceProp.Name <> targetProp.Name Then Continue For
 
      ' Only try to set property when able to read the source and write the target
      If sourceProp.CanRead And _
            targetProp.CanWrite Then
        ' We want to leave System types alone
        If sourceProp.PropertyType.IsClass And _
              Not sourceProp.PropertyType.FullName.StartsWith("System.") Then
          Dim sT As Type = Type.GetType(sourceProp.PropertyType.AssemblyQualifiedName)
          Dim tT As Type = Type.GetType(targetProp.PropertyType.AssemblyQualifiedName)
 
          Dim params(0 To 1) As Object
          ' If property is an array or a list, we need to treat it different
          If sourceProp.GetIndexParameters().Length = 0 Then
              params(0) = sourceProp.GetValue(source, Nothing)
              params(1) = targetProp.GetValue(target, Nothing)
 
            targetProp.SetValue(retValue, _
                                GenericCopyProperties(sT, tT).Invoke(Me, params), _
                                Nothing)
          Else
            Dim count As Integer = GetType(sourceType).InvokeMember("Count", BindingFlags.GetProperty, Nothing, source, Nothing)
            For i As Integer = 0 To (count - 1)
              Dim obj As Object() = New Object() {i}
              params(0) = sourceProp.GetValue(source, obj)
              If target IsNot Nothing Then
                params(1) = targetProp.GetValue(target, obj)
              End If
 
              retValue.GetType().InvokeMember("Add", BindingFlags.InvokeMethod, Nothing, _
                                              retValue, New Object() {GenericCopyProperties(sT, tT).Invoke(Me, params)})
            Next
          End If
        Else
            targetProp.SetValue(retValue, sourceProp.GetValue(source, Nothing), Nothing)
        End If
      End If
 
      Exit For
    Next
  Next
 
  Return retValue
End Function

The function above is a generic function as I needed to call some methods on the Type of the objects. I wrapped the dynamic creation of the generic method in the following function.

1
2
3
Private Function GenericCopyProperties(ByVal sourceType As Type, ByVal targetType As Type) As MethodInfo
  Return Me.GetType().GetMethod("CopyProperties").MakeGenericMethod(sourceType, targetType)
End Function

Lastly, the snippet below shows how to call the function.

1
2
3
4
5
Dim params(0 To 1) As Object
params(0) = sourceObject
params(1) = targetObject
 
targetObject = GenericCopyProperties(sourceObject.GetType(), targetObject.GetType()).Invoke(Me, params)

Personally, I love the mix of different techniques here. Reflection, dynamic methods, recursion and generics are very powerful on their own, but combined there’s some real magic waiting to be discovered :)

I discovered that there is an (in development) implementation of the Lisp/Scheme language for the Dynamic Language Runtime (DLR). Pretty cool. I very much enjoyed the Lisp courses I followed at uni. The language looks worse than Perl but is actually quite simple once you get your head around it. As one of the primare languages in Artificial Intelligence research, it has been used for all kinds of funky research projects. One of the coolest ones in my opinion is John Koza evolving Lisp programs using Genetic Programming (GP) to solve various (mathematical) problems. Software writing software..how cool can you get?

IronScheme can be found here.

Another day at DevDays 2008. Everyone could definately feel the previous day in our bones but we weren’t any less excited. I was forced to skip a session because I was about to fall down but hey, you win some, you lose some.

ASP.NET MVC Framework by Alex Thissen

The ASP.NET MVC Framework is Microsoft’s implementation of the well-known and widely-used MVC pattern, used amongst others by Ruby on Rails and Java Swing. In my opinion, it is the way to go for future web development, but opinions differ. One of the most-heard peeves against the MVC Framework is to do with Views. The MVC Framework does not use the existing post-back model, does not support view-state and no page lifecycle in its views. That means that you’ll need to do more manual work in your views. In essence MVC uses the classic ASP model. I for one like this development but I can imagine hardcore web developers not liking the additional work. According to Scott Guthrie the MVC team will provide us with MVC-aware controls sometime in the future.
Speaking of Scott, the best place to start exploring the MVC Framework is his 4-part tutorial, which can be found here:

Instrumentation for Tracking User Experiences by David S. Platt

In this talk David, tired of getting ‘no’ for an answer when asking Microsoft for the code to their Customer Improvement Program service did what any self-respecting developer would do: he rolled his own implementation. The result is a very lightweight, easy to use user experience tracking framework. One key feature is that the framework makes it very, very difficult indeed to store any kind of sensitive user data such as credit card numbers. What you do not log, you cannot store and what you cannot store you cannot leak, even by accident. The code of the framework is freely available. Currently I think you’ll need to contact David to get your hands on it but he might post a link to download it in the future.

IronPython and Dynamic Languages by Harry Pierson

Being a big fan of dynamic languages, Ruby in particular, I was really looking forward to this presentation. Harry Pierson is the PM of the IronPython team and clearly very enthusiastic about IronPython, IronRuby and the Dynamic Language Runtime (DLR). He showed us some basic Python magic. One of the coolest things I saw was how simply importing the CLR extends existing objects at runtime. This is really something you should see so I will get up an example sometime soon. Also, embedding IronPython in for example C# takes about 4 lines of code. I can see a lot of applications for this, one of them being able to fool around with some algorithms without needing to recompile your project. Or how about using IronPython or IronRuby to implement business rules (something they are both very strong at)? Awesome.
There’s really no good way to show just how cool IronPython and IronRuby are. You should check it out for yourself.

DevDays 2008 (held in the RAI convention centre in Amsterdam) is typically the most-looked-forward too events in the Dutch developer community. And yet this was my first DevDays to visit. Previous years I was too busy, or I realized it was “that time of the year” again too late (I have similar experiences with the Deventer book market, but that’s a different story). Anyway, I was looking forward to the event immensely. I wasn’t disappointed. Below are some of the presentations I visited.

Keynote “Why Software Sucks” by David S. Platt

Where David Platt is concerned, I think the world is divided into two camps; you either hate the guy or you think he’s a genius. After roughly the first 3 minutes of his talk about why software today sucks I am part of the latter. In a whirlwind of anecdotes, pleas and tell-it-like-it-is (sorry Dr. Phil), David makes it very clear that he is passionate about the quality of software today. And he’s got a pretty good picture on why it’s crap and how to make it better. Most of his ideas are plain common sense, a trait sadly lacking in a lot of software companies today. The main of his ideas revolves around a single phrase: Know thy user, for he is not thee. A software user doesn’t care about how clever we are in getting things done. He just wants it done. Fast, easy and without having to think about it. I am cutting some corners here obviously. If you want to know more, find the presentations online (I will post the links as soon as I get my hands on them) or get his book from Amazon.

Advanced Debugging with Visual Studio by Ingo Rammer

Just about every .NET developer knows about the Visual Studio Debugger and uses it on a daily basis. Not doing so is somewhat like digging a hole with a teaspoon. It’s slow, it’s a lot of hard work and once you’re finished you’re stuck in a hole you cannot get out of without help. The VS Debugger is like using the CanDig CD21 mini excavator. It’s easy, looks pretty impressive and ends you up at the edge of the hole instead of in it. Oh, and did I mention you can dig a whole lot more holes in the same amount of time?
Ingo Rammers took us on a guided tour of the VS Debugger. Starting off with the standard breakpoints whom we all know and love he pointed out that there’s a lot more to breakpoints than meets the eye. For example, did you know you can opt to run a macro, any macro, doing anything you can think of you want done, every time a breakpoint is hit? I sure didn’t, and the possibilities of that are just about limitless. Or that you can hide your properties from showing up in the Debugger? Encapsulate your entire class in a proxy to make it look and feel completely different while Debugging? I am definately going to get back to this in a next post, but in the meantime the presentation should be out there somewhere.

WCF on the WEB: Using REST and JSON with WCF by Peter Himschoot

REST (Representational State Transfer) is becoming more prominent in the .Net Framework. In this talk, Peter Himschoot showed us how to REST-enable your WCF (Windows Communication Foundation) services. It’s surprisingly easy: reference a DLL, tag on some attributes, change your binding and presto, we can do REST. So why is REST important to us anyway? SOAP’s fine, isn’t it? No, it isn’t. One of the only reasons I ever use SOAP is interoperability. In my opinion, it is bulky, it is difficult to maintain and it is slooooow. And, with REST, it turns out to be pretty much superfluous. Interoperability with REST is even better than SOAP. I’ve done a lot of BlackBerry programming in my days. The BlackBerry runs on J2ME. J2ME doesn’t like SOAP (or at least it didn’t when I was working with it). And I don’t like to have to build huge, error-riddled XML strings every time I do a request to the server. But J2ME likes HTTP. And it likes GET and POST and DELETE and all those other HTTP verbs that make our lives so much richer. And REST doesn’t need more than that to work. It will literally work with any client that knows how to set up a HTTP connection, at a fraction of the cost in time, complexity and maintainability.
I am sure you’ve noticed I like REST. And I don’t like SOAP. But in all fairness, SOAP isn’t evil. It’s just horribly over-used. There’s more roads that lead to Rome. And to me, REST is like flying business class while SOAP is like taking the bus (and if you know the state our public transport system is currently in, that’s saying something).
I haven’t mentioned JSON yet. As Peter puts it, JSON is XML with anorexia. Strip away those pesky tags and you are pretty much left with JSON. JSON is key-value pairs. JSON is data centric where XML is document centric. And that can make a pretty big difference if your bandwidth is severely limited. As my colleague pointed out, JSON doesn’t support attributes. But who needs those anyway? Attributes in XML are syntactic shortcuts for having to write full tags. See? Even the XML people think XML is bloated.
I will be toying around with REST and JSON more in the future. More to come.

UPDATE: Peter has posted the link to his two presentations here.