Recently I?ve been arguing in different forums that I think that VB.NET hides implementation details to the obscure. I?ve argued that due to that hide and seek; many vb.net developers never fully understand the nature of .NET.
One example where this is obvious is the Handles keyword.
As many of you probably know, event handling in .NET is implemented using delegates and delegate instance variables. The semantics in handling events is that you hook a function pointer (delegate) to the event using the syntax;
btnAdd.Click += new EventHandler(btnAdd_Click);
Now this isn?t possible in VB.NET 1.x since it doesn?t support operator overloading. Therefore instead they got the AddHandler keyword which is a wrapper to the above C# syntax. That is all fine and dandy. The problem is the following syntax;
Sub btnAdd_Click(object sender, EventArgs e) Handles btnAdd.Click
? Do stuff
End Sub
Just looking at this without assuming knowledge of the C# syntax and the delegate implementation; I would read this as the method being the controlling party in the event handling process. This is of course wrong, but I do believe that the syntax above does encourage that kind of thinking. Especially if you come from a VB6 background where the method WAS the controlling party from a developer standpoint.
Additionally this actually hides the delegate implementation totally and a developer will be surprised when delegate details do matter in their event handling. I encounter this a lot when I deliver courses, Vb.Net developers has less understanding about delegates then their C# colleagues.
Johan Lindfors (MSFT) challenged me on this standpoint today at MSDN Live in Örebro after I promoted another simplification in C# 2.0:
btnAdd.Click += btnAdd_Click;
The difference as I see it is that with this syntax you will know who the controlling party is and you will actually use a delegate like syntax. A more direct and pedagogic approach which forces the developer to learn the basics.
Speaking of 2.0; in the next version of Vb.Net, Microsoft is introducing more simplifying features. I?m talking about the Microsoft.VisualBasic.MyServices classes. This is a nice tool to have but it also, in my opinion, has a tendency to hide too many details. A classic example is the FileSystem class which blesses the Vb.Net developer with ignorance about streams, which are a central part of the .Net framework and crucial knowledge.
I?m not saying that help and easy programming is a bad thing, I?m just arguing that there?s a danger in over simplifying programming so that important concepts and understanding get lost.
I also want to encourage you to always look at the implementation details before you use any kind of simplification, having the ?know how? greatly reduces the headache when you need to find bugs in you?re simplified code.
|