- 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
I can see that this post has generated very interesting responses.
Personaly I'm fun of if...else solution. I really doubt that parsing command line arguments is the real bottle neck of any application. I would focuse on improving other parts of the application.
Admin
I hated java and perl so much, I moved just about everything over to python. Now I love what I do every day.
Nothing is inevitable, every problem is not a nail, and every tool is not a hammer.
Admin
all of this is probably inspired by MS' remarks on string-Hashcodes: For example, the implementation of GetHashCode provided by the String class returns unique hash codes for unique string values. (This obviously cannot be true because GetHashCode returns a 32-bit integer value and many more string values exist)
Admin
The real WTF is that the programmer went to all the trouble of converting the string "single" to an int and the user is still required to type out the entire word. Why solve the problem of needing 7 precious bytes to represent the constant "single\0" and not save the user a few keystrokes while you're at it?
The obvious solution is to create an int based on the first two chars and simply ignore the rest of the chars in the parameter. Then document that all parameters may be shortened to two characters, and re-label it a "feature": The user need only type "si" when they mean "single".
The program's behavior will also be well-defined for any conceivable input, since colliding parameters will be obvious and easy to find. Most of the time you want to avoid hash collisions, but in this case a definitive "yes, that will collide" is better than "I doubt it, but I'd need to compute its hash to be certain".
The only catch is that if you want to map two chars directly to an int16 with no conversion (in an embedded system, that's probably the simplest and best way to do it), you have to know which byte order the system uses.