Comment On Are You Sure?

"There was a minor bug in one of my company's applications," Craig M wrote, "for whatever reason, it just hung after the 'Are you sure?' prompt." [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Re: Are You Sure?

2008-08-13 08:04 • by Sellnosoup (unregistered)
yar~!

I mean - first!!!11

Re: Are You Sure?

2008-08-13 08:04 • by ingenious (unregistered)
Fist!! Are you sure you want to read this comment?

captcha: ingenium

Re: Are You Sure?

2008-08-13 08:05 • by T $
indeed

Re: Are You Sure?

2008-08-13 08:05 • by DaveAronson
With all due apologies to Katherine Hepburn, it's very yar. As in, "yarrrrggghhhh!!!!" This looks like clbuttic "paid by the line" code.

Re: Are You Sure?

2008-08-13 08:06 • by snoofle
If you're note going to limit yes/no responses to y/n/FileNotFound, at least put the possibilities in a list/loop.

Sheesh!

Re: Are You Sure?

2008-08-13 08:09 • by ParkinT
It would have been more 'Enterprisey' if the responses were read from an XML file.

Re: Are You Sure?

2008-08-13 08:11 • by ParkinT
and whether the developer in question really had nothing better to do.

Nah
Nope
Nada
Uh ah
no way
negative
absolutely not
Fer sure
Non
Don't think so

Re: Are You Sure?

2008-08-13 08:13 • by BlueKnot
What, no provision for "maybe"?

Re: Are You Sure?

2008-08-13 08:14 • by andrewbadera
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

Re: Are You Sure?

2008-08-13 08:18 • by Grovesy
211710 in reply to 211707
BlueKnot:
What, no provision for "maybe"?


and no provision for FileNotFound

or

NotTrueOrFalse

Re: Are You Sure?

2008-08-13 08:19 • by Anon. (unregistered)
Are You Sure? true

Invalid answer.

Are You Sure? はい

Invalid answer.

Are You Sure? FILE_NOT_FOUND

Invalid answer.

Re: Are You Sure?

2008-08-13 08:25 • by tdittmar
211714 in reply to 211709
andrewbadera:
Soooooo .... why did it hang? Looks like valid script to me.

Hm. Enter "Y" and see what happens... Is my sarcasm detector broken?

Re: Are You Sure?

2008-08-13 08:25 • by grg (unregistered)
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 !!

Re: Are You Sure?

2008-08-13 08:29 • by Migala (unregistered)
211716 in reply to 211715
grg:
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 !!



4|\|D d0|\|'7 Ph0R937 7|-|3 r34L |-|4X0R5!

Re: Are You Sure?

2008-08-13 08:30 • by pytechd (unregistered)
211717 in reply to 211715
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!

Re: Are You Sure?

2008-08-13 08:34 • by darkmattar
211718 in reply to 211714
tdittmar:
andrewbadera:
Soooooo .... why did it hang? Looks like valid script to me.

Hm. Enter "Y" and see what happens... Is my sarcasm detector broken?


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....

Re: Are You Sure?

2008-08-13 08:36 • by Volmarias
You've got to wonder the level of boredom required to make such an extensive list, and whether the developer in question really had nothing better to do."


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!

Re: Are You Sure?

2008-08-13 08:37 • by Patryk Zawadzki (unregistered)
The hanging part was obviously because of a large number of corporate customers typing "fa shizzle" over and over again.

Re: Are You Sure?

2008-08-13 08:38 • by aliquam (unregistered)
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...

Re: Are You Sure?

2008-08-13 08:40 • by dbugger
211723 in reply to 211717
pytechd:
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!


For real speed, all possible responses should have been entered in an Oracle database.

Re: Are You Sure?

2008-08-13 08:41 • by I'm Cornfused (unregistered)
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?

Re: Are You Sure?

2008-08-13 08:42 • by tom (unregistered)
if (answer.equals("DON'T QUESTION MY ORDERS, MACHINE")) {
return snivelingObesiance();
}

Re: Are You Sure?

2008-08-13 08:42 • by Berrs (unregistered)
Ah, how nice to see software made to be used by humans, not machines!

Re: Are You Sure?

2008-08-13 08:45 • by Jota (unregistered)
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>

Re: Are You Sure?

2008-08-13 08:47 • by Mee (unregistered)
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!

Re: Are You Sure?

2008-08-13 08:50 • by Matey (unregistered)
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

Re: Are You Sure?

2008-08-13 08:54 • by Smash King
Where are Toejam & Earl's clbuttic YUP and NOPE ?

Re: Are You Sure?

2008-08-13 09:00 • by anon (unregistered)
211737 in reply to 211726
and pirates, please think of the pirates

Re: Are You Sure?

2008-08-13 09:01 • by James (unregistered)
This would save you all those annoying "if" statements. Not that that's even TRWTF.


if(Array.IndexOf(
new string[]{ "yes","y","ok","why not", [...], "yar" },
userInput.ToLower())
> -1)
{
// do the yes stuff
}
else
{
// do the no stuff
}

Re: Are You Sure?

2008-08-13 09:02 • by TakeASeatOverThere
if (answer.equals("yar")) {
return true;

Obviously the application was designed for pirates.

Re: Are You Sure?

2008-08-13 09:04 • by A Nonny Mouse
return confirm('Are you sure?');

or is it just me. the less human input the better, methinks

Re: Are You Sure?

2008-08-13 09:06 • by James (unregistered)
211742 in reply to 211721
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.

Re: Are You Sure?

2008-08-13 09:07 • by G (unregistered)
fist

first

fist!

first!

fisteleven

last... upside down

fst

ffs second

boring

old

brillant!

Re: Are You Sure?

2008-08-13 09:07 • by Someone (unregistered)
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!

Re: Are You Sure?

2008-08-13 09:07 • by KiwiGeek (unregistered)
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.

Re: Are You Sure?

2008-08-13 09:08 • by brillohead (unregistered)
211746 in reply to 211721
aliquam:
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...


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...

Re: Are You Sure?

2008-08-13 09:12 • by Daniil (unregistered)
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"));

Re: Are You Sure?

2008-08-13 09:13 • by Fried (unregistered)
211749 in reply to 211738
James:
This would save you all those annoying "if" statements. Not that that's even TRWTF.


if(Array.IndexOf(
new string[]{ "yes","y","ok","why not", [...], "yar" },
userInput.ToLower())
> -1)
{
// do the yes stuff
}
else
{
// do the no stuff
}


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.

Re: Are You Sure?

2008-08-13 09:19 • by mjparme
The real WTF is that he didn't use a regular expression!

Re: Are You Sure?

2008-08-13 09:22 • by Steve (unregistered)
211754 in reply to 211716
Migala:
4|\|D d0|\|'7 Ph0R937 7|-|3 r34L |-|4X0R5!
That made my eyes hurt.

He missed the point

2008-08-13 09:27 • by Darron (unregistered)
211755 in reply to 211752
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.

Re: Are You Sure?

2008-08-13 09:28 • by mauve (unregistered)
211756 in reply to 211746
brillohead:

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...


True, if you intern the input string:
http://java.sun.com/javase/6/docs/api/java/lang/String.html#intern()

Re: Are You Sure?

2008-08-13 09:29 • by bjolling
211758 in reply to 211748
Daniil:
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"));


So how would you handle "yeah right!" ?

Re: Are You Sure?

2008-08-13 09:30 • by Vechni
The real WTF is that people are making suggestions to this code on how to improve it.

Re: Are You Sure?

2008-08-13 09:33 • by Liam Clark (unregistered)
211760 in reply to 211705
ParkinT:
Nah
Nope
Nada
Uh ah
no way
negative
absolutely not
Fer sure
Non
Don't think so


Does this mean someone other than me remembers Torin's Passage?

Re: Are You Sure?

2008-08-13 09:35 • by Enkurs (unregistered)
One major WTF in this is what kind of input the prompt wanted? Were the user supposed to type an answer?

Re: Are You Sure?

2008-08-13 09:36 • by Adam (unregistered)
That looks like it'll be a bitch to internationalize

Re: Are You Sure?

2008-08-13 09:37 • by Buddy (unregistered)
211764 in reply to 211745
KiwiGeek:
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.


I like it!

supposing you ain't ready

Re: Are You Sure?

2008-08-13 09:37 • by cconroy
211766 in reply to 211739
TakeASeatOverThere:
if (answer.equals("yar")) {
return true;

Obviously the application was designed for pirates.


What's Pirate for "no"? "Nar"?

Re: Are You Sure?

2008-08-13 09:38 • by Kermos
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.
« PrevPage 1 | Page 2 | Page 3 | Page 4Next »

Add Comment