- 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
yar~!
I mean - first!!!11
Admin
Fist!! Are you sure you want to read this comment?
captcha: ingenium
Admin
indeed
Admin
With all due apologies to Katherine Hepburn, it's very yar. As in, "yarrrrggghhhh!!!!" This looks like clbuttic "paid by the line" code.
Admin
If you're note going to limit yes/no responses to y/n/FileNotFound, at least put the possibilities in a list/loop.
Sheesh!
Admin
It would have been more 'Enterprisey' if the responses were read from an XML file.
Admin
Admin
What, no provision for "maybe"?
Admin
Soooooo .... why did it hang? Looks like valid script to me.
Ed. Note: to clarify, this code had nothing to do with it - it was an unrelated bug somewhere else in the app; this was just code Craig uncovered while investigating
Admin
and no provision for FileNotFound
or
NotTrueOrFalse
Admin
Are You Sure? true
Invalid answer.
Are You Sure? はい
Invalid answer.
Are You Sure? FILE_NOT_FOUND
Invalid answer.
Admin
Admin
THE REAL WTF IS THEY DID NOT HANDLE THE CASE WHERE THEY WERE AN IDIOT AND HAD THEIR SHIFT-LOCK ON.
THEN YOU'D NEED ALSO THE UPPER CASE COMPARISONS TOO !!
Admin
4||D d0||'7 Ph0R937 7|-|3 r34L |-|4X0R5!
Admin
This needs to be in XML. And there needs to be XSLT to transform the XML values into their mixed-case companions. And for speed, the XML has to be processed by an external tool during the build process that emits massive IF structures and compiles it -- XML lookups are too slow -- it combines the best of both worlds -- the ease of use of XML and the speed of the mighty IF statement!
Admin
Since "Y" is the very first thing listed.... I sure hope MY sarcasm detector is broken. I'm being kind and assuming the UserInput class automatically casts 'answer' to lowercase as the first thing it does.
I bet if we could see the program's input window, and meet the persons that the programmer has to deal with, this would make more sense. It reminds me of situations at my own work anyway... The input dialog asks the user to enter [Y] or [N], but one user doesn't like this and requests that 'Yes' and 'Yep' be allowed. So the programmer adds them - see the first if-block. Next the user asks for 'Ok' to work too... see next if-block. Now the programmer just gets irritated and puts in every form of YES that he can think of off the top of his head, out of a fit of code rage. It's like road rage, except with more semi-colons.
It sure looks like something I'd do in the above scenario just to be an asshat....
Admin
Boss: Developer! Developer: Yes, boss? Boss: This confirmation prompt is broken! It asks me if I want to proceed, and then doesn't do anything! Developer: Are you pressing Y, or typing yes? Boss: Of course not! I'm typing "yep". Your code should be smart enough to figure that out, and if not, maybe you need another job. Developer: Sigh....
5 minutes later
Developer: Ok, it recognizes "yep" Boss: Well it's too bad that you're still an idiot, because it doesn't understand "ok"
Developer sees where this is going...
5 minutes later
Developer: Ok, try again Boss: That's more like it! Ha! It even got "yar"! Excellent job!
Admin
The hanging part was obviously because of a large number of corporate customers typing "fa shizzle" over and over again.
Admin
the .equals() is to slow to be used in a large series of if statements...
You should only use it when you know the majority of the test will be true.
If you know the majority of the test will be false use the == operator which is slower when true, but twice as fast when false...
Admin
For real speed, all possible responses should have been entered in an Oracle database.
Admin
I'm also not seeing why it would hang... (unless a 1 ms delay constitutes a 'hang')
The if structure isn't nested, and doesn't call some horribly recursive function... so unless it's running on a TI-83 or something, the 26 if statements really shouldn't take any time at all to run through.
I'm also not sure which language this is, and whether or not .equals() will actually compare the values of the strings. If it's checking for the objects to actually be the same instance or something weird like that, then yeah, there's going to be issues.
Any explanations, anybody?
Admin
if (answer.equals("DON'T QUESTION MY ORDERS, MACHINE")) { return snivelingObesiance(); }
Admin
Ah, how nice to see software made to be used by humans, not machines!
Admin
Perhaps this was just a frustrated developer who was tired of dealing with bug reports.
QA: When I typed "yes" it didn't work. Please fix.
Developer: OK, "yes" should work the same as "y" now, and "no" should be the same as "n".
QA: When I typed "ok" it didn't work. That is standard for dialog boxes. The prompt should be more forgiving. Please fix.
Developer: But this isn't a dialog box... oh, whatever. There, now "ok" and "cancel" should be accepted as well.
QA: The text on the page before mentions the word "proceed", so the prompt should accept that as well. Please make the prompt more forgiving.
Developer: Fine. I'll make the prompt more forgiving. You want to type "proceed"? Here, you can type "proceed"! How about "affirmative"? You want "affirmative"? Or maybe "positive"? What about pirates? Aye? Do we have any pirates using our software? Gotta think of the pirates, yep! Hey, "yep" -- you want "yep" too? Have a "yep"! Have whatever you want! Is that forgiving enough? IS THAT FORGIVING ENOUGH?
QA: When I just hit enter, nothing happens. Hitting enter should default to "yes".
Developer: <hangs self, and Craig M is hired to replace him>
Admin
What about a dialog box that says "Do you want to cancel" and the user wants to "Proceed", it would cancel!
That is the real WTF!
Admin
1: - we're geeks here, and you left out the part that actually causes the hang! We demand more complete code snippets
2: - The code actually accepts "yar" for an affirmative. To borrow from failblog, this one wraps right around to WIN
Admin
Where are Toejam & Earl's clbuttic YUP and NOPE ?
Admin
and pirates, please think of the pirates
Admin
This would save you all those annoying "if" statements. Not that that's even TRWTF.
Admin
Admin
return confirm('Are you sure?');
or is it just me. the less human input the better, methinks
Admin
This is a user input routine, not the inner section of some important loop. For all your trouble you'll be lucky to shave milliseconds off with that approach. Better to write it to be as readable and easy to change as possible.
Admin
Admin
Why didn't he use equalsIgnoreCase()? He could have handled thousands more permutations without any more lines of code. I demand the ability to answer yeP, aFFiRMaTIvE, or YAR!
Admin
This reminds me vagely of the time I was developing a scripting language for a game I was working on and decided to put all the different possible variations of "not" in that I could thing of, including my favourite, "ain't". I like to tell myself that it was the only scripting language to ever have ain't as a keyword. If you're bored, the language functioned something like this... if #var1 not #var2: but "not" could be switched with many different keywords, such as "<>", "!=", "is not", "ain't". "If" could also take many forms, such as "supposing". ... I also had a list of true variables. and False. There was no "FileNotFound", however. ... I was young and foolish.
Admin
yes, because checking if the memory location of the input is the same as the memory location of my static strings is going to give me exactly the result im looking for...
Admin
OK, really, do none of you ever do something like that? My question is, why didn't the developer use a Map for this? Its faster. Its rather thorough list. I slack:
return (val != null && (val = val.trim().toLowerCase()).length() > 0 && val.startsWith("y"));
Admin
A new String Array each time it checks the user input, and it always defaults to false. Hmmm... I think I'd go for the database option over this.
Admin
The real WTF is that he didn't use a regular expression!
Admin
Admin
It's a game. Every developer who passes through this code is supposed to add one word to each of the true and false lists.
Admin
True, if you intern the input string: http://java.sun.com/javase/6/docs/api/java/lang/String.html#intern()
Admin
So how would you handle "yeah right!" ?
Admin
The real WTF is that people are making suggestions to this code on how to improve it.
Admin
Does this mean someone other than me remembers Torin's Passage?
Admin
One major WTF in this is what kind of input the prompt wanted? Were the user supposed to type an answer?
Admin
That looks like it'll be a bitch to internationalize
Admin
I like it!
supposing you ain't ready
Admin
What's Pirate for "no"? "Nar"?
Admin
Ok the first WTF is, if it's a yes/no prompt why not have two buttons? A combo box containing yes/no a choices? Why a text field?
The things that users can do with text fields are just horrendous. Don't ever give users text fields unless you have to! I have to deal with a bunch of crap stored into text fields that should have been combo box choices. Did you know there are apparently 38 ways to specify "Ground" as a shipping method? Try to run a query with garbage like that in a database to see all shipments that left or arrived via ground shipping.