There is currently a thread running on the [aus-dotnet] mailing list about some of the features in C#, those that are there, and those that are perceived to be missing. Of course, someone had to bring out the OO stick and start waving it around and Dr. Neil sagely pointed out that its possible to write OO code without a language that supports OO concepts – its all about the developers state of mind.
Minas Casiou from CSC pointed out that even things like GOTO can be useful too. He’s right! Computing depends on them, although I can’t really say that I haven’t put the boot into the humble GOTO construct in the past, in fact when I see it in code I tend to have a WTF moment.
Fundamentally, all programmers ever do is build abstractions, GOTO and its kind just happen to live at a layer in that abstraction stack that most of us don’t feel comfortable working in any more. It made me think of this little quote that we use during our IS.NET course.
“Between keyboard, screen, and hard drive, I build palaces of abstractions. Layer upon layer, and when the abstractions become simple enough to do my so-called work, I feel happy. When the abstractions let me down, I refine them. Hopefully I can wrestle these abstractions into submission and accomplish what I want. When everything is done, I will have built a shiny new abstraction for someone else to use to do so-called work. If lots of people use my abstraction in their palaces, I will be very happy.” – Source.
The problem is that most abstractions leak (read about the law of leaky abstractions here), and when they do you find yourself dealing with things that you thought you had moved on from.
Take a look at the .NET runtime for example. If you take a surf through the .NET Framework with .NET Reflector you’ll often find “goto” instructions in the code – in fact, if you take your IL raw – pretty much every method will jump from one location in code to another labelled position. Most of the time these are your humble language constructs like if blocks and while loops – but sometimes you’ll find one that doesn’t seem to correspond to any higher level abstraction (that’s right – if is a high level abstraction).
I’m not certain, but I suspect that this isn’t just some compiler quirk, but instead, its actually a hand crafted optimisation where the developers of the .NET Framework found that their blunt C# or VB.NET instruments were insufficient and they needed sometime more precise.
Basically – the abstraction leaked. Think about this the next time you go to criticise the GOTO statement – while the developer might be using it for evil things – the construct is certainly not evil itself.