• HerrDerSchatten (cs)

    // This is a frist comment, which is a really good thing to have! // In case this is not returned bool isFirst= false; return isFirst.tostring()

  • Rocky (unregistered)

    My brain just melted and it's not because of the heatwave...

  • Medinoc (cs)

    I think these comments are the least WTF part of the function. But they do provide useful insight as to just how WTF it is.

  • Chris Allen-Poole (unregistered)

    Strikes me as more of a child's game, or an early dev. learning project than having an actual real application.

  • Flabberghasted (unregistered)

    As far as I can tell this entire function should:

    1. not even compile. Unless C(# or ++) allows break statements after a return.
    2. It doesn't even work as it current returns whether the first character of the string is a vowel instead of whether the string contains a vowel.

    In Java this can be done in one line: org.apache.commons.lang.StringUtils.containsAny(theword, "aeiou");

    I assume that this is also the case in the language used.

  • Doozerboy (unregistered) in reply to Flabberghasted
    Flabberghasted:
    As far as I can tell this entire function should: 1) not even compile. Unless C(# or ++) allows break statements after a return. 2) It doesn't even work as it current returns whether the first character of the string is a vowel instead of whether the string contains a vowel.

    In Java this can be done in one line: org.apache.commons.lang.StringUtils.containsAny(theword, "aeiou");

    I assume that this is also the case in the language used.

    in c# it'd be something like

    var exists = myString.IndexOfAny(new []{'a','e','i','o','u'}) != -1;

  • giammin (unregistered)

    I can't believe this is real

  • Doozerboy (unregistered) in reply to Flabberghasted
    Flabberghasted:
    As far as I can tell this entire function should: 1) not even compile. Unless C(# or ++) allows break statements after a return.

    C# does allow that, but a break would be wholly redundant after a return.

  • Taco (unregistered)

    Why, why, why, would you check on vowels in a word? I cannot think of a sane reason.

    Anyone?

  • foo AKA fooo (unregistered)
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?
  • Josh (unregistered)

    In ASCII land these implementations would somehow work. Ever dealt with code running on inputs from multiple locales? Similar to the "in my IDE more actions are linked to a hotkey than in yours" wars, where non US layout keyboard users end up in RSI hell.

  • Studley (unregistered)

    It's good that extraBool2 is so handy and important that it's never referenced.

  • Schol-R-LEA (cs) in reply to Doozerboy

    In C, one can (mis-)use strtok() to get the same effect:

        return (strtok(s, "aeiou") != NULL);
    

    It isn't what the function is meant for, but it will do the job. Seriously, how hard is that?

  • cpedro (unregistered) in reply to foo AKA fooo
    Comment held for moderation.
  • Pista (unregistered)

    I still can't believe that this is from a real business application. I'm almost sure that this comes from some programming class assignment. Or from a "programmer" who never made it past the CS-101 level.

  • RFox (unregistered)

    Am I the only one that gets a headache when the comments run right into the code without whitespace

    // this kind of comment makes my head hurt if (a == b) { ... } // This kind of comment I'm ok with since the } is // almost as good as whitespace but a=b; // got lost in the midst of the comments.

  • foo AKA fooo (unregistered)

    You will hear from PETA about that Labrador comment.

  • Anonymousy (unregistered) in reply to Chris Allen-Poole

    "Strikes me as more of a child's game, or an early dev. learning project than having an actual real application."

    Ah, you mean 'organically grown' proprietary production code running 54% of all our businesses!

  • win (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    You will hear from PETA about that Labrador comment.

    I've honestly met many Labrabors with better analytical skills than some of my colleagues so I take offense at this slight against Labradors.

    (and... I don't belive this code can be real, there are some things that don't strike me as things an idiot would do, seems more like it is constructed to be WTF-y)

  • ANON (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?

    It will never go into this case anyway. One character is transformed to a string and the string is compared with "bcdfghjklmnprstvwxz" which is always false.

    Captcha: CAPIO - This comment was provided by Capio Obvious

  • Jim (unregistered) in reply to ANON
    ANON:
    foo AKA fooo:
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?

    It will never go into this case anyway. One character is transformed to a string and the string is compared with "bcdfghjklmnprstvwxz" which is always false.

    Captcha: CAPIO - This comment was provided by Capio Obvious

    ..and it wouldn't matter anyway because any character other than a, e, i, o, u and y will do this:

            default :
          //in any other case we should always return something as it's excellent good practice to have
          //things like this
              does = false;
              return does.ToString();
              break;
    
  • A (unregistered)

    ...unless the parameter value passed was null, in which case it would throw an exception on the very first "if" statement.

  • Rodnas (unregistered) in reply to Anonymousy
    Anonymousy:
    "Strikes me as more of a child's game, or an early dev. learning project than having an actual real application."

    Ah, you mean 'organically grown' proprietary production code running 54% of all our businesses!

    Only 54%? We should consider ourselves very lucky.

  • That admin guy (unregistered) in reply to Taco
    Taco:
    Why, why, why, would you check on vowels in a word? I cannot think of a sane reason.

    Anyone?

    If seen stuff like this when the developer is trying to determine if an input contains actual words or just random crap. This follows the logical fallacy: 'All words have at least one vowel; therefor any text that contains a vowel must be a word'.

  • anon (unregistered) in reply to Pista

    We just had a guy come (and go) that wouldn't even have been able to produce this.

    This is what happens when you let the suits handle recruiting.

  • Leo (unregistered)
    Comment held for moderation.
  • 1337 H4CK3R (unregistered) in reply to Taco
    Taco:
    Why, why, why, would you check on vowels in a word? I cannot think of a sane reason.

    Anyone?

    "Invalid password. Your password must contain at least 1 lowercase letter, 1 uppercase letter, 2 numbers, 5 symbols, 1 vowel, and your first born child.

  • Ron (unregistered)

    So, according to this bulletproof code, "And" does not contain a vowel. Neither dos "The", since it doesn't search past the first letter.

    If you're going to return a boolean with a .ToString(), then I think you should at least do it up right:

    HasAVowel("fubar") should return "true", and HasAVowel("FUBAR") should return "TRUE"

  • SpasticWeasel (unregistered) in reply to Doozerboy
        public bool Why(string s)
        {
            return s.ToLower(CultureInfo.CurrentCulture).Any(c => ("aeiou").Contains(c));
        }
    
  • JonC (unregistered)

    Wow, I've seen some bad code in my time, but I struggle to believe this is the output of a professional developer.

  • Adam_Weishaupt (unregistered) in reply to Taco

    Could be a wheel of fortune thing?

  • foo AKA fooo (unregistered) in reply to SpasticWeasel
    SpasticWeasel:
    public bool Why(string s) { return s.ToLower(CultureInfo.CurrentCulture).Any(c => ("aeiou").Contains(c)); }
    Brillant! Pretend to support localization, but don't actually. Please merge this with the original function and you're hired!
  • KattMan (cs) in reply to foo AKA fooo
    foo AKA fooo:
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?

    Nope, try Qat, yes it is a word.

  • mozzis (unregistered) in reply to Ron

    Why do so many of you think it only looks at the first char in the string? Did you miss the 'foreach' ?

  • Mike (unregistered)

    TRWTF is all the ToString() calls on string literals.

  • foo AKA fooo (unregistered) in reply to mozzis
    mozzis:
    Why do so many of you think it only looks at the first char in the string? Did you miss the 'foreach' ?
    You're right. Everyone else is stupid. Or they just haven't learned those newfangled multi-return functions.
  • foo AKA fooo (unregistered) in reply to KattMan
    KattMan:
    foo AKA fooo:
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?

    Nope, try Qat, yes it is a word.

    D'oh, we're talking about q, not Q! AKA woosh!

  • Sizik (unregistered) in reply to mozzis

    Did you miss the 'return' in each case?

  • Sizik (unregistered) in reply to mozzis
    mozzis:
    Why do so many of you think it only looks at the first char in the string? Did you miss the 'foreach' ?
    Sizik:
    Did you miss the 'return' in each case?

    missed the quote button

  • 1337 H4CK3R (unregistered) in reply to mozzis
    mozzis:
    Why do so many of you think it only looks at the first char in the string? Did you miss the 'foreach' ?

    I hope you're trolling.

    If you're that thick, note that the "loop" always returns during the first iteration due to the default case.

  • 1337 H4CK3R (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    Or they just haven't learned those newfangled multi-return functions.

    Now I'm imagining this as Python code with yield everywhere instead of return.

  • Zog (unregistered)

    Vowels...so I noticed it doesn't check for cases where 'y' behaves as a vowel, and assumes the English language.

    If they were clever then they'd check the locale and pull in the list of vowels and exceptional cases from some database...I guess with the following schema

    language : varchar(200), aisvowel : boolean, eisvowel : boolean . . .

    ;-)

  • Anonymii (unregistered) in reply to A
    A:
    ...unless the parameter value passed was null, in which case it would throw an exception on the very first "if" statement.

    Maybe then we should use the Null2 function so it won't crash all the time ?

  • Matt Westwood (cs)

    So "crwth" has no vowel in it?

  • Anon (unregistered) in reply to Taco
    Taco:
    Why, why, why, would you check on vowels in a word? I cannot think of a sane reason.

    Anyone?

    T nsrs y dn't mk ths knd f mstk?

  • eman_ruoy (unregistered) in reply to KattMan
    KattMan:
    foo AKA fooo:
    Now this isn't all bad. Because the developer (who is no longer with Roger's company) was wise enough to include the default case in the switch statement, the fact that he forgot that 'q' was a letter didn't introduce any bugs. Whew. That was close.
    //I know what you think I should check for the letter
    //q here, but note that q is always being followed with the
    //letter of u which is already a vowel as you can see from my brillant
    //code above for example as in quiz or question
    //so i really don't need to check for the letter q this is called an
    //optimization which is always a very good thing to have
    
    Fixed?

    Nope, try Qat, yes it is a word.

    Or Qatar. You know, the country.

  • Shill (unregistered) in reply to Doozerboy
    Doozerboy:
    Flabberghasted:
    As far as I can tell this entire function should: 1) not even compile. Unless C(# or ++) allows break statements after a return. 2) It doesn't even work as it current returns whether the first character of the string is a vowel instead of whether the string contains a vowel.

    In Java this can be done in one line: org.apache.commons.lang.StringUtils.containsAny(theword, "aeiou");

    I assume that this is also the case in the language used.

    in c# it'd be something like

    var exists = myString.IndexOfAny(new []{'a','e','i','o','u'}) != -1;

    Both of you geniuses failed to handle the use of y as a vowel.

  • Chris P. Peterson (unregistered)

    There are 3 logic errors in HasAVowel. And I consider proper line spacing as important as good comments. Still better than most code out there though.

  • neminem (unregistered)

    I see the real WTF: he missed the most important one!

    That guy:
    //this creates my "extraBool" which is a fantastic way of handling additional
    //logics so that as well as true & false, we can also have like no value string 
    extraBool = "No text value".ToString();
    //we also have another extrabool for invalid values. this is handy and very important 
    string extraBool2 = "Invalid value".ToString();
    string extraBool3 = "File Not Found".ToString();
    

    Much better!

  • neminem (unregistered)

    Also that you can't use quote to quote people that weren't in the thread here, unlike every other commenting system ever. >.>

Leave a comment on “Too Much of a Bad Thing”

Log In or post as a guest

Replying to comment #:

« Return to Article