- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Correct, operators are not polymorphic. I've heard of languages where they are, but at least in C decended languages it wouldn't make a lot of sense. Reason being - how would you decide which of the parameters to do your virtual dispatch on? The left side operand or the right? Or both somehow?
Operators are basically just static functions that take the two parameters as input. You can make them behave polymorphically by calling a polymorphic function, if you like. Then you can choose how the polymorphic method is dispatched.
Admin
Simply gold. That's the worst WTF ever.
Admin
name is not the key, but the object he is looking for... you missed that one... ;)
Admin
OK, I'll play defender of the WTF. Perhaps the original coder wanted to return true in the case the hashtable contained an entry with key corresponding to the input parameter but the value associated with it was null.
Admin
Except it doesn't do that. For that behavior, the line:
if ((((string)tempHt[en.Key]) == name))
would have to be changed to:
if (en.Key == name))
Admin
You are correct in your definition of polymorphic. However, polymorphism determines the appropiate method to call at run-time depending on the run-time type of the instance of the object you are calling the method on. operator==( ) happens to be static, so there is no instance of an object and hence it isn't polymorphic. The objects to be compared are passed as arguments, as in operator==(string str1, string str2). You can see why operator==(object obj1, object obj2) is called instead in the case where 2 strings are compared through object references.
At least that's the way I think it happens [;)]
Admin
I've seen a relatively experienced programmer do the same thing. The blame, in my opinion, goes to the Microsoft documentation of HashTable: There is no LookUp-like method defined! This is dysfunctional.
After a frustrated programmer does a research project on the .NET hashtable, it turns out the LookUp function is implemented by a C# indexer: the [] brackets. This doesn't appear in the Microsoft documentation, further reinforcing the notion that Microsoft documentation is often worthless.
Admin
From Microsoft's Documentation:
Hashtable.Item PropertyGets or sets the value associated with the specified key.
[C#] In C#, this property is the indexer for the Hashtable class.
Admin
The least they could have done was break after found = true. Jeesh.