Toxic Elephant

New Language Features in .NET

Posted by matijs Wed, 06 Sep 2006 16:36:00 GMT

One of the reasons I have a dislike for both Java and the main .NET langauges, VB.NET and C#, is the ridiculous verbosity involved in creating and filling an object variable. Typically, what you get is something like:

Some.Deep.Namespace.Structure.SomeClass foo = new Some.Deep.Namespace.Structure.SomeClass();

The repitition of the class name makes the horrid namespace nesting twice as bad. And no, this is not about typing, this most definitely is about reading.

So, you can imagine my pleasant suprise when, belatedly, I came across a discussion of var. Basically, var is a new keyword in the upcoming C# 3.0 that allows you to do this:

var foo = new Some.Deep.Namespace.Structure.SomeClass();

And then, and this is the good part, the C# compiler will infer that foo is a variable of type Some.[..].SomeClass and will complain if you try to store anything else in it1.

Same type safety with half the reading. Excellent.

Now, that’s not all. It turns out there’s a lot more interesting stuff coming in C# 3.0, making it more concise and powerful.

1 Yes, I’m aware that ML does this and even more.

Posted in  | no comments | no trackbacks

Abstractions

Posted by matijs Fri, 01 Sep 2006 16:31:00 GMT

One of the reasons I enjoyed learning Ruby is that it allowed me to understand and then use new abstractions. Not all of these are absent from other languages, but Ruby made them comprehensible for me, so they became part of my toolbox, if you will.

What this means is that I can write code that does the same thing in fewer lines, and this in turn makes it easier to keep an overview of all of that code.

At the same time, there is a whole group of programmers who completely seem to have missed the abstractions train, or even the abstractions road. They’re plowing along in the fields, barely able to divide their code into subroutines beyond the ones forced upon them by their IDEs. These are the people who write (whitespace added for clarity):

do_d

do_a
do_b
do_c

do_e

do_a
do_b
do_c

do_f

If the same five things need to be done a hundred times in a given source file, that’s five hundred lines right there. The abstraction of the subroutine is not an automatism for them.

So what does it matter whether people get taught programming in Java or in Ruby, if no-one stops them from creating thousand-line subroutines? I really wouldn’t know.

Posted in  | no comments | no trackbacks

Toxic Elephant is Matijs van Zuijlen's weblog.

Powered

Categories

Archives