C# 4.0′s dynamicity

I just found an article ranking highly on Hacker News (my favourite read) concerning the release of C# 4.0 – you can find it on blogs.msdn.com. On this blog Microsoft claims a couple of highly sophistacated new features. Being the spoiled guy I am, they just seem natural to me. Since they started their article with the words “The dynamic keyword is a key feature of this release.”, let me demonstrate the new features in a really dynamically typed language where they have been around for quite some time: Python

Dynamic

C#

 
                        dynamic contact = new ExpandoObject();
                        contact.Name = "Patrick Hines";
                        contact.Phone = "206-555-0144";
                        

Python

 
                        class contact: None
                        contact.Name = "Patrick Hines"
                        contact.Phone = "206-555-0144"
                        

Optional (or Default) Parameters

C#

 
                        public static void SomeMethod(int optional = 0) { }
                        SomeMethod(); // 0 is used in the method.
                        SomeMethod(10);
                        

Python

 
                        def some_method(optional = 0): pass

                        some_method()
                        some_method(10)
                        

Named Arguments

C#

 
                        var sample = new List<String>();
                        sample.InsertRange(collection: new List<String>(), index: 0);
                        sample.InsertRange(index: 0, collection: new List<String>());
                        

Python

 
                        def foo(bar, foobar): None

                        foo(bar='asdf', foobar=12)
                        foo(foobar=12, bar='asdf')
                        

I honestly know that a comparison of a statically typed language on the CLR and an interpreted dynamic language doesn’t account for too much. But since Microsoft is making a fuzz about dynamic being the keyword of the new release, I felt the urge to drop this note.

The Python code was tested with v2.5 – that’s the oldest installation I’ve got. However, it’s old enough, because .NET didn’t even have decent IPC back then (i.e. Named pipes were added in .NET 3.5).

Well, that’s my rant for the night – I’m going back to teaching myself a real programmers language(Clojure) – as you should, too(;


    If you liked the article, follow me on twitter here
twitter_preek
Tags: ,

5 Comments

6 Responses to “C# 4.0′s dynamicity”

  1. sraybell Says:

    The point? To rag on C# for introducing dynamic when others already had it? He even poked at C# not being serious, as he put it, because the FRAMEWORK didn’t have IPC. Um, okay?Look, with some portion of dynamic being usefel everywhere and with the growing demand thereof, it was prudent to add these features. Heck, optionals and named were hotly contested features since 1.0 due to introducing mechanisms that were ultimately not important at the time. It introduces complexity, etc.

    Maybe C# should give him a pony, too.

    There were many other trumpeted features in C# as well as the framework as a whole.

    This comment was originally posted on Hacker News

  2. preek Says:

    My point being? You gave yourself the answer.If I may quote: ".. were hotly contested features since 1.0" This was around the year 2k IIRC. They honestly took 10 years to include basic features and claim to have a business proof framework? Yeah, maybe – for ex-Java golems who still have WinXP developing _and_ server machines. As we all know, those would be.. the real business guysg

    This comment was originally posted on Hacker News

  3. preek Says:

    My point being? You gave yourself the answer.If I may quote: ".. were hotly contested features since 1.0" This was around the year 2k IIRC. They honestly took ±10 years to include basic features while claiming to have a businessproof framework? Yeah, maybe – for ex-Java golems who still have WinXP developing _and_ server machines. As we all know, those would be.. the real business guys.

    As to the "other trumpeted features" – I can’t recall any on the beforehand mentioned release notes. Maybe the "improved COM" support. Have fun calling Excel for generating your CSV files.

    This comment was originally posted on Hacker News

  4. preek Says:

    My point being? You gave yourself the answer.If I may quote: ".. were hotly contested features since 1.0" This was around the year 2k IIRC. They honestly took ±10 years to include basic features while claiming to have a businessproof framework? Yeah, maybe – for ex-Java golems who still have WinXP developing _and_ server machines. As we all know, those would be.. the real business guys.

    This comment was originally posted on Hacker News

  5. sraybell Says:

    This shows an axe to grind with C#, and not for the sake of C#. While you’re information and insights were definitely interesting, I don’t think that it really amounted to anything beyond, "Gimme a pony!".That’s just my opinion, though.

    This comment was originally posted on Hacker News

  6. Captain Code Says:

    You’re not ranting enough!
    More harsh language!
    ;)

Leave a Reply