Posted by & filed under .Net.

So I see both Andrew, Nick and Alex
J
have some thoughts on languages, and of course Rowans post sparked it off… and
people talk about beautiful languages, mentioning expressiveness
in the same breath. 

Personally I love how expressive Ruby is - I think
potentially because I got my first exposure to ruby after reading
Why’s poignant
guide
 a while back (I see there are new chapters
…oooh) which was quite surreal compared to how I say learnt C++
(from reading the Borland Turbo C++ manual when I was 11, also my
first exposure to OOP)…

When I code in ruby I feel like I’m telling stories… I dig that
:)

So Alex J mentioned that extension methods let us achieve much of
the syntactic sugar that ruby provides (though obviously in
ruby’s case this isn’t so much syntactic sugar as core mechanisms
in the language itself) – and of course Lambda expressions are
helping too, but does expressive == good 100% of the
time?   I don’t think I’m qualified to say, but I can’t
help but feel that a language which is very expressive, isn’t
necessarily the easiest to manipulate and refactor, so I may not
be as productive and it may not feel as fluent to me… I quite
liked this resharper horizons post which suggests that tooling
support should probably influence future language design – could
that requirement possibly fight against an increased level of
expressiveness in a language, will compromises need to made, or
is nirvana just around the corner?

As for C# vs VB.Net – large clumsy keywords are only a
probablem until something like Resharper steps in… when I’m
developing I see a lot of unusued space on the right hand side of
the editor with C#… if VB.Net fills it up, and I’m not typing any
harder to get there, why should I care – hell it’ll probably make a
VB.Net Resharper Jedi look more impressive then the C# equivalent,
he’ll be producing more characters ;o)

OK, well I figured this post should at least have some code…
I’d feel uneasy otherwise… so how about:

public static class CommonExtensions{    public static Action<Action<int>> LoopTo(this int start, int end)    {        return new Action<Action<int>>(action => To(start, end).ForEach(i => action(i)));    }     public static IEnumerable<int> To(this int start, int end)    {        if (end < start)            for (int i = start; i > end - 1; i--)                yield return i;        else            for (int i = start; i < end + 1; i++)                yield return i;       }     public static void ForEach<T>(this IEnumerable<T> sequence, Action<T> action)    {        foreach (T item in sequence) action(item);    }     public static void PrintLine(this object o)    {        Console.WriteLine(o);    }}


So now we could try and do this….

// ruby(10..20).each { |i| puts i }// C#10.LoopTo(20) ( i => i.PrintLine() );


Alas I don’t think C# will ever match ruby in this game, no
matter how we try to nudge it there… and until the development
community figures out where the healthy place is to draw the line
in the attempt, we may be doing more harm then good by pushing
for it, sacrificing discoverability/maintainability for
expressiveness.   Maybe that’s just dogma, and
expressiveness makes code inherently easier to maintain in the
first place, so we don’t need to care…. time will tell.

Of course I could be wrong, I am a little sleepy ;o)

Comments are closed.