Welcome to CrankyGoblin.Com Sign in | Join | Help

Public Class GeoffAppleby

Inherits Microsoft.VisualBasic.MVP : Implements IBrainFart
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)
Posted: Tuesday, 15 February 2005 12:15 PM by Geoff Appleby
Filed under:

Comments

Ranjan said:

<OffTopic>
Just imagine somebody taking the pains to make the compiler understand the context in which "using" is used :)
As Anders Heijlsberg said, a computer language is just like our languages. They have their flaws.
Interestingly, if you consider Japanese, a word can have upto 8 different meaning, differing only by the tone in which you speak.
</OffTopic>

I think the problems come with people shifting from VB to C# or vice versa. We have a guy here who had to do that, and he hates these things. Newbies just learn it anyway. I think my opinion is the opposite of yours, but thats just an experience. Maybe I am wrong.
# February 15, 2005 1:22 PM

Geoff Appleby said:

As I said, I can't place myself in a newbies shoes. You make a good point actually - i'm not anti-C#, i'm merely pro VB, so anything that different is hard to judge impartially :)
# February 15, 2005 2:52 PM

JosephCooney said:

Don Box in "Essential .NET vol. 1 - The Common Language Runtime" refers to this as keyword overloading IIRR and even gives props to VB.NET for using the more descriptive "shadows" keyword. I'd still take C# over VB.NET in a heartbeat ;-).
# February 15, 2005 6:36 PM

Duncan Smart said:

What you're describing here is not "overriding" it's "hiding".
# February 15, 2005 6:42 PM

Geoff Appleby said:

Joseph: Yay Don!
# February 15, 2005 6:43 PM

Scott Galloway said:

Just be glad 'set' isn't used commonly in C# (http://dictionary.reference.com/search?q=Set) - I agree though until you get it they're conceptually problematic. Luckily you would mostly not use these keywords until you're a tad learned. I can still count on my fingers the number of times that I've hidden a parent method's implementation - and I mostly only using the 'using' naming keyword thing when using DirectX...
# February 15, 2005 8:37 PM

Darrell said:

The tradeoff is additional words which have a narrower meaning versus fewer words whose meaning depends on context. Like you said, since experienced people know what is going on, it doesn't matter. Newbies, well, I'll defer to Einstein, "Everything should be made as simple as possible, but no simpler." Why do we have to shield newbies from difficult programming matters? Besides, having words that mean different things depending on context is similar to polymorphism, and we don't try to shield newbie programmers from that, do we? Well, besides letting them write procedural (or worse) code in an OO language and let them think they are doing OOP. :)
# February 15, 2005 9:54 PM

Daniel Moth said:

VB has the same issue with bitwise/logical:
And Or
(versus in C#: && & || |)
# February 20, 2005 8:05 PM

Mitch Denny said:

Awwww, but its one of my favorite interview questions.
# February 24, 2005 6:28 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

To submit your comment, click on these pictures:
  • Geoff has an idea
  • Happy Geoff
  • Geoff's tongue
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Gaptcha Image - No Peeking! Gaptcha Image - No Peeking! Gaptcha Image - No Peeking!
Can't recognise the people in these pictures? Look here for a quick introduction.
There's a time limit for you to get your comment submitted before this set of pictures expires. If you think it's been longer than 10 minutes, get some new pictures first (you won't lose what you've typed so far).
Get some new pictures 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS