• Sellnosoup (unregistered)

    yar~!

    I mean - first!!!11

  • ingenious (unregistered)

    Fist!! Are you sure you want to read this comment?

    captcha: ingenium

  • (cs)

    indeed

  • (cs)

    With all due apologies to Katherine Hepburn, it's very yar. As in, "yarrrrggghhhh!!!!" This looks like clbuttic "paid by the line" code.

  • (cs)

    If you're note going to limit yes/no responses to y/n/FileNotFound, at least put the possibilities in a list/loop.

    Sheesh!

  • (cs)

    It would have been more 'Enterprisey' if the responses were read from an XML file.

  • (cs)
    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
  • (cs)

    What, no provision for "maybe"?

  • (cs)

    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

  • (cs) in reply to BlueKnot
    BlueKnot:
    What, no provision for "maybe"?

    and no provision for FileNotFound

    or

    NotTrueOrFalse

  • Anon. (unregistered)

    Are You Sure? true

    Invalid answer.

    Are You Sure? はい

    Invalid answer.

    Are You Sure? FILE_NOT_FOUND

    Invalid answer.

  • (cs) in reply to andrewbadera
    andrewbadera:
    Soooooo .... why did it hang? Looks like valid script to me.
    Hm. Enter "Y" and see what happens... Is my sarcasm detector broken?
  • 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 !!

  • Migala (unregistered) in reply to grg
    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!

  • pytechd (unregistered) in reply to grg

    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!

  • (cs) in reply to tdittmar
    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....

  • (cs)
    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!

  • Patryk Zawadzki (unregistered)

    The hanging part was obviously because of a large number of corporate customers typing "fa shizzle" over and over again.

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

  • (cs) in reply to pytechd
    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.

  • 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?

  • tom (unregistered)

    if (answer.equals("DON'T QUESTION MY ORDERS, MACHINE")) { return snivelingObesiance(); }

  • Berrs (unregistered)

    Ah, how nice to see software made to be used by humans, not machines!

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

  • 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!

  • 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

  • (cs)

    Where are Toejam & Earl's clbuttic YUP and NOPE ?

  • anon (unregistered) in reply to Berrs

    and pirates, please think of the pirates

  • 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
    }
    
  • (cs)
    if (answer.equals("yar")) { return true;
    Obviously the application was designed for pirates.
  • (cs)

    return confirm('Are you sure?');

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

  • James (unregistered) in reply to aliquam

    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.

  • G (unregistered)
    fist
    first
    fist!
    first!
    fisteleven
    last... upside down
    fst
    ffs second
    boring
    old
    brillant!
  • 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!

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

  • brillohead (unregistered) in reply to aliquam
    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...

  • 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"));

  • Fried (unregistered) in reply to James
    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.

  • (cs)

    The real WTF is that he didn't use a regular expression!

  • Steve (unregistered) in reply to Migala
    Migala:
    4|\|D d0|\|'7 Ph0R937 7|-|3 r34L |-|4X0R5!
    That made my eyes hurt.
  • Darron (unregistered) in reply to mjparme

    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.

  • mauve (unregistered) in reply to brillohead
    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()

  • (cs) in reply to Daniil
    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!" ?

  • (cs)

    The real WTF is that people are making suggestions to this code on how to improve it.

  • Liam Clark (unregistered) in reply to ParkinT
    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?

  • Enkurs (unregistered)

    One major WTF in this is what kind of input the prompt wanted? Were the user supposed to type an answer?

  • Adam (unregistered)

    That looks like it'll be a bitch to internationalize

  • Buddy (unregistered) in reply to KiwiGeek
    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

  • (cs) in reply to TakeASeatOverThere
    TakeASeatOverThere:
    if (answer.equals("yar")) { return true;
    Obviously the application was designed for pirates.

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

  • (cs)

    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.

Leave a comment on “Are You Sure?”

Log In or post as a guest

Replying to comment #:

« Return to Article