The Rubification of C#

Chad Myers gave me a nice little surprise by using my surname in his blog post "Moore on the Anonymous Delegate Approach" about an approach to make his statically-typed C# code more easily testable. I struggled with how best to respond because the subject of his code experiments really demonstrates some of the things I've been thinking about C#'s evolution for a while now. So while this isn't a direct response to his post, its something I've been wanting to say for a while now.

Chad started out by showing how you can use anonymous delegates to encapsulate your logic, and then swap out the delegates in his test cases so he can verify the dependent objects work properly. So he is essentially swapping the implementation of the code his object has a reference to. The fly in the ointment is that only the original anonymous delegate can access all the internal data in his object, so once you swap out the object's original anonymous delegate, the object becomes ineffective. (Unless your logic is dead simple, like the kind you use when you are writing code demos.)

The thing I really like about Chad's code is that he's getting really close to using anonymous delegates as closures, and I really love closures. I believe if Microsoft would (or could) add closures to the C# language (and idioms) that C# would be better for it. But closures aren't embraced by C#. I understand that he is finding new ways to solve the testability problem with static languages, and while I enjoy his ingenuity, I'm starting to think that C# is moving too far from what it is. My concern is that as C# tries to be all things to all people, it simply stops being as useful.

Coincidentally, Tim Bray posted his thoughts on adding closures to Java yesterday, and he said many of the things I've been thinking about in regards to C# and Ruby. The only caveat I'd make on applying Tim's thoughts to C# and .NET is that Java Generics != .NET Generics. Essentially, C# is an 80% language, and I'm totally okay with it. Ruby is also an 80% language, although a much different 80%. Making C#'s 80% overlap overlap Ruby's 80% as much as possible seems kinda wrong.

Tim's favored approach to improving Java is to work on a multi-language VM, not the core language itself. .NET is already ahead because it has facilities for interoperating multiple languages. Therefore I don't think we should focus on improving C#, but we should start focusing on using the right tool for the right job; meaning the right language. Don't get me wrong, I appreciate the fact that C# is taking on many Rubyisms in an effort to improve. But C# will never be Ruby, and really it never should. My hopes are that the DLR enables C# and IronRuby to not just co-exist but integrate well.

In this Channel9 video Robert Martin and Chad Fowler discuss dynamic vs. static languages at JAOO 2007. You should watch this video now. In it, Uncle Bob was asked if he was excited about the new functional programming features of C#; specifically LINQ. His response? "I'm about as excited about that as I am about Fortran 95." His point was that by the time the new Fortran was released he had already moved on and it was no longer relevant to him. That is certainly how I feel about C#; the more features they add, the more desperate it looks, and the less I feel like investing myself in it.

Static languages have failed. They aren't dead, but they aren't the future. You can only fight a language so long before its time to move on.

Published:
12.17.07 / 21PM
Updated:
12.17.07 / 21PM
Tags:
.net alt.net ironruby ruby

5 comments

Chad Myers 12.17.07 / 21PM
(crossposted comment) Mike, I don't disagree at all. I'm certainly not advocating anyone go this way, I'm more just thinking out loud and trying to unlearn static and learn dynamic, but through a familiar and comfortable (to me) language like C# :)

Bertrand Le Roy 12.18.07 / 15PM
I usually enjoy reading your blog but wow. "Static languages have failed"? Just wow. Don't you think that viewpoint might be just a little myopic? Because they don't work for you or for the microcosm you're hanging out in doesn't mean it doesn't work for the rest of the world. Static languages have been and continue to be very successful. Maybe it would be a little more productive to recognize the merits of each side before making definitive judgements like this one. It might also help the dynamic language world to recognize major advances in language design (which imo Linq is) so that they can incorporate similar concepts in their own favorite technology. One thing that can be said from the C# team (which from our own microcosm looks very very far from "desperate") is that *they* know how to keep an eye on the other side and incorporate what looks interesting, while not compromising the integrity of the language. In that respect, anonymous types capture an essential aspect of dynamic languages while remaining strongly-typed (and thus keeping IntelliSense working). You might also want to consult the documentation for anynymous methods, which do capture surrounding local variables (since 2.0), which in my book is pretty much what a closure is. Don't want to look aggressive or anything, sorry if I did, not my intention. Keep up the good work and the provocative thinking.

Mike Moore 12.18.07 / 22PM
Hey Bertrand, thanks for leaving a comment! I hope my view isn't myopic, it certainly isn't mine alone. The last 20+ years have been dominated by static languages like C++, Java, and C#. I believe we are in the midst of a dynamic language revolution and I expect the landscape to look dramatically different in 3 to 5 years. I'm talking about the entire IT landscape, not just the .NET or J2EE landscape (although they will look different as well). I can spend an entire post replying your comment, so I did so here. I hope I didn't scared you off! :)

Chris Brandsma 12.19.07 / 10AM
If Static languages have failed, are dynamic really the answer? More often there are cases where I want both. For me, the true value of a language is how it leads you to a successful outcome. In my biased view of the world, the more open a language is, the harder it becomes to follow ("why did you override the 'if' statement? "Because I could"), and the less likely you are to get to a favorable outcome. Now, good developers will write good code in any language, and bad developers can mess up anything. I want a language that allows freedom for the good, and shackles for the bad. Is that so much to ask?

Mike Moore 12.19.07 / 12PM
Chris, if you focus on making your code easy to read, clear, and communicate your intent, you won't have situations like you describe regardless if the language supports it or not. IMO the language can't (and shouldn't) enforce you to write good code or not write bad code.