When Words Collide
Has anyone ever noticed that sometimes words mean different things depending on their context?
There's a few common examples I can think of in the English language.
- Left. Do I mean a direction (go left, on the left, left side) or a remainder (left out, left over)?
- Right. Do I mean a direction, or correctness?
- Port. This is a classic one. Is it a place ships go, an alcoholic beverage, a direction (left in boatspeak), or a schoolbag (apparently Queenslanders use this one)?
Contextually, it's fine. You can determine what it means based on the context of the rest of the words.
But is this something we really need in programming? I got a hell of a surprise today, and I thought I'd share it.
In VB, if you want to override a property from a base class, you use the keyword Shadows. While VB has the keyword Overrides available, it can only be used in situations where method signatures don't match - if the method signatures match (except for return type), then you need to shadow.
In C#, I discovered, to override a property in a base class, you use the keyword new.
What the?
I can think of another instance in C# where this happens too - the using keyword. One use is to shortcut namespaces, the other is to make a nice block around an object that supports IDisposable.
Now, as I said above in regards to the English language, contextually it's still clear what's going on - but do we need this type of confusion, especially for newbies? Experienced programmers will have no trouble with it, certainly, but it still sets my teeth on edge.
I can't think of anywhere this happens in VB (I'm certainly not saying VB is innocent in this respect, I just can't think of any :) Perhaps VB constructors could fall into this category (Public Sub New()) although I think it's less evil - it's still contextually related in that Sub New() gets called when you call New, if you get what I mean.
I'm sure this is really no big deal, but I have to question the reasons behind it. Contextually, you can tell them apart. In usage, you understand why the word was used (I'm using this namespace as opposed to this object, I'm creating a new property rather creating a new object) but is it really that wise?
What do people think? I'm sure experienced programmers have no trouble with it (or don't even care), but is this a good move as far as newbies are concerned? I can't put myself in a newbies shoes anymore, so I can't answer it myself :)
Certainly, however, my opinion is that keywords should be used once, not shared between concepts :)
Listening to: bad seed - metallica - (4:05)