12
2009
C# eye for the Java Guy
I’m sitting here sipping on a decaf and hacking on a large C# codebase. What has become of me?
Don’t worry, I’m not losing my religion, Java will always be my perfect dish (along with Groovy and Grails for the condiments). But often my consulting work takes me places where exotic dialects are spoken. Lately I’ve helped a client with a bunch of C++ and C# integration work on Win32. It doesn’t feel like home, but there’s some very interesting landscape here. I’ve enjoyed working the C# so much, it’s fast become my “learn a language” project – and I’m really getting into it.
So what’s to love?
Well first of all the language is remarkably similar to Java, but with all the features that should already be in there if they ever decide to actually modernise the JDK. Properties and Delegates (typesafe function pointers) dramatically and elegantly solve the whole event handling mess. Lambdas deal with a stack of the common use cases for closures in a format that groovy programmers will find very familiar. Ever operator overloading is employed cleverly. It hurts me to admit that Microsoft know what they’re doing here, but this is really a fantastic modern programming language! Enough faint praise.
So, you’re a Java guy who needs to get up to speed on C#/dotnet in a hurry? There’s a bunch of good resources that you need to get your hands on to get started. First go buy a good book:
- Pro C# 2008 and the .NET 3.5 Platform, Fourth Edition (Apress) by Andrew Troelsen
Recommended to me by wmacgyver, this book has turned out to be a fantastic find. Wastes no time on “non programmer” content, but introduces the language, the libraries, and the frameworks in a deep dive manner (it’s a massive book at around 1300 pages — but it’s the only intro page that a Java guy is going to need to get started).
With a book to read and learn from, go grab a copy of Visual C# Express Edition – it’s a free download and runs fine inside of VirtualBox on OSX.
So where are all your familiar tools?
- For builds, everything is done via MSBuild. Think Ant, but less classy. This is the file the IDE uses to manage the project, but you can happily launch it from the commandline. There’s no Maven equivalent.
- For unit testing, MSUnit is provided in the Pro version of Studio and above. Annotation-based Unit testing framework that JUnit 4.x folk will find familiar. Add the odd [TestClass] and [TestMethod] annotation judiciously and you’re off and running.
- For coverage reports, the folk at testdriven.net have done a nice plugin (but it only works on the pro version of studio.
- For mocking, you probably want to check out Moq, though people who like record/replay style mocking might want to try Rhino mocks
Anways, before I get too entrenched in all this Microsoft stuff, I need to retreat to some

An article by Glen





I’m also having a similarly pleasant experience with C#. I’ve been able to get by with a cheat sheet and a bit of googling, but I’m starting to think that I should invest some time in learning the language properly – thanks for the book tip. If I could have C# on the JVM that would be great for server based code that needs to be statically typed. MVC .Net is also a comfortable fit for those coming from the Grails/Rails worlds.