Tuesday, February 19, 2008

C# here we come

This is not a rant on how sucky M$ (we all know that so now we can move past that). Furthermore after three weeks can hardly call myself an expert on the .Net framework. The upside to this of course is that in a few months I can write a follow up and really rip into M$.

Anyway; C# what can I say about this language. When it first came out Anders Heljsberg made great pains to say that that C# was a derivative of C++. Of course we knew better, after all it was language with garbage collection with interfaces and single inheritance and a runtime systems which compiled to intermediate code for a VM, suspiciously like Java.

Well guess what? after having worked with it for a bit I actually agree with Anders. From what I've been able to see C# is basically a cleaned up C++.

Now make note of the fact that I call C# a "cleaned up" C++ no a "clean" C++. Anders seems to have made sure that he has stuck everything and the kitchen sink into C# just like they used to do in C++.

Furthermore when you start getting used to the C# way you have this eerie feeling that you've been down this road before, not because of pointers or memory leaks but because of all those other pointless language features that Java did away with for good reason.

Here's a taste:

- Empty extension constructors which just invoke the parent constructor with a specialised syntax for doing just that.

- Namespaces which have no other logical mapping to an external construct other than just being a name just to make us plebs navigate through Visual Studio's glorius solution explorer.

- Explicit declaration of methods which can be overriden together with explicit declaration for methods which are overriden.

- .Net has a physical packaging system called an assembly (like a jar but with versioning and such like), of course they added extra visibility modifiers to make the visibility within assemblies more usefull other than to the occasional arb case, and - as far as I can see with my newbie eyes - don't offer any real value, kinda like the "friend" operator.

- Macros. Nuff said. At least C# handles doesn't require funny workarounds for definition of namespaces.

Then of course there are the features to make it more "OO" for C++ people like:
- Integer based ENUMS
- Structs
- Delegates: method pointers with attitude
- Structs for primitive types so you get some of features of proper objects for base types but will all the pain of not having them as proper objects.

And my favourite feature of all: Partial classes, basically a feature that M$ put into the language to facilitate GUI generation so that you can split up classes and the compiler merges the two declarations at compile time. Of course the problem is that when you look at a class and see it's declared partial you have the sick feeling that there is more here...

Having said that there are a few things that C# does get right:
- Generics: no wildcards and built into the language.
- Delegates are cleaner than anonymous classes even if both Java and C# should just have had lambda expressions to begin with.
- .Net 3.5 has all those funky functional features like type inference and Lambda expressions.

I't still early days though, I'm sure there is more here.

Watch this space...

No comments: