Posts tagged ‘.net’

Visual C# .net - some interesting language features

So after being a member of the anti Microsoft club for a long time, I finally found myself wanting to write some COM code and decided to pick up a 1350 page C# book and start learning something that any self respecting java developer would never do, learn C# and the .net platform.
The first thing that struck me about C# is the syntactical similarity to Java. All Algol family languages C,C++ etc. share the same heritage so the similarity was not so shocking - but everything from constructor chaining, single class inheritance model and signature based method was strangely similar. In fact I can safely say that if you are a java developer with any experience, you should be up and running with C# in a matter of days if not hours. Similarities apart - here are a few things that I love about C#:

  • Operator overloading - this is such an awesome tool when you are writing a DSL or an engineering based application. Groovy allows this for the JVM but C# natively supports it for the .net CLR.
  • Implicit and explicit casts - this is an extension to the operator overloading but how many times have we found ourselves writing a utility class that has a single argument constructor that takes a String or a numeric type. What an ingenious idea - using such a feature is common in dynamic languages. I have found myself using the “as” keyword in groovy all the time. With C# you can customize how implicit casting is done.
  • Delegates - with ruby on rails and grails radically changing the way web applications are done its quite amazing to imagine a language without delegates and closures. (yes I know all java lovers will say they never needed it), but the fact of the matter is most powerful frameworks either do their magic using template patterns, byte code manipulation or AOP. The concept of closures or delegates is missing from Java (thank god they are finally working on it). C# although not a full fledged functional language has delegates and there is a lot of really cool stuff you can do with them. What I absolutely loved is delegate chaining and multicast delegates. What an absolutely awesome concept built into the language. The listener pattern can be very elegantly implemented with this feature.

I have just begun with C# - as time goes on I am sure I will be adding more stuff to the list. The features are unfortunately not compelling enough for me to pick up C# for any client or live projects that I am doing. I can achive the same things and much much more by using poly-language groovy/java mix. Not to mention the millions of free lines of code and the flexibility that comes with the java platform. But I am very happy with C# so far, definitely not a total waste of time.