• Rob (unregistered)

    Yes, it's definitely not great code. String literals that are being converted into strings, chars being converted into strings that are being matched against single character strings, etc, etc... Classic rookie mistakes.

    But hey, at least the author was decent enough to leave comments. (I'd rather spend my time deleting useless obvious comments than having to deal with variable names like 'data' or 'ID') It's more than obvious that the author that he (albeit truly misguidedly) took effort into writing this piece of code.

    But then I noticed this:

    catch (Exception) { return "error unknown".ToString(); }

    ...now THIS is the most infuriating part. Generally, I'm more than willing to refactor poorly written chunks of code (and even confront and educate the original author if he's still among the ranks!) but I'm absolutely sick of the "Let's sweep exceptions under the rug!"-school of thought countless of devs seem to be getting away with.

  • Norman Diamond (unregistered) in reply to Carrie
    Carrie:
    Norman Diamond:
    Compare the w sound in "no way" with the w sound in "vowel". Vowel's w sounds like a vowel.
    How do you get that? The 'ow' in vowel is just the same as in now. The w is the, well, w sound on the end of the ow bit. Not as distinct as in 'no way' I'll admit, since the e is normally unstressed so the 'wel' gets all run together into one sound like cowl or howl.
    Then compare "vow well" and "vowel".
  • Wouter (unregistered) in reply to Schol-R-LEA
    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?

    ITYM strcspn:

    return (strcspn(s, "aeiou") != strlen(s))

    strtok changes s, which may not be what you want.

    strcspn, on the other hand, calculates the length of the initial component of s which does not consist of the characters given in its second argument. If that is the same length as the length of the string, you don't have any vowels.

  • Neil (unregistered) in reply to Wouter
    Wouter:
    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?

    ITYM strcspn:
    return (strcspn(s, "aeiou") != strlen(s))
    strtok changes s, which may not be what you want.

    strcspn, on the other hand, calculates the length of the initial component of s which does not consist of the characters given in its second argument. If that is the same length as the length of the string, you don't have any vowels.

    Slightly more streamlined version:
    return s[strcspn(s, "aeiou")];
    As a bonus, it returns the first vowel found or 0 if there is no vowel.

  • Carrie (unregistered) in reply to Norman Diamond
    Norman Diamond:
    Carrie:
    Norman Diamond:
    Compare the w sound in "no way" with the w sound in "vowel". Vowel's w sounds like a vowel.
    How do you get that? The 'ow' in vowel is just the same as in now. The w is the, well, w sound on the end of the ow bit. Not as distinct as in 'no way' I'll admit, since the e is normally unstressed so the 'wel' gets all run together into one sound like cowl or howl.
    Then compare "vow well" and "vowel".

    Yes?

  • _darkstar_ (unregistered)

    Sorry. I just don't believe that this hasn't been made up. It is way beyond standard WTF level.

  • owlstead (unregistered) in reply to RFox

    I already get a headache when end of line comments are actually used at the end of a line. It plays hell with formatting if I decide to refactor anything (never mind the fact that they may be placed behind or after the line).

    Place them in front of the line please, not on the line itself. Preferably after an empty line.

  • Norman Diamond (unregistered) in reply to Carrie
    Carrie:
    Norman Diamond:
    Carrie:
    Norman Diamond:
    Compare the w sound in "no way" with the w sound in "vowel". Vowel's w sounds like a vowel.
    How do you get that? The 'ow' in vowel is just the same as in now. The w is the, well, w sound on the end of the ow bit. Not as distinct as in 'no way' I'll admit, since the e is normally unstressed so the 'wel' gets all run together into one sound like cowl or howl.
    Then compare "vow well" and "vowel".
    Yes?
    Compare 1 vowel followed by 1 consonant and 1 vowel alone.

    "Hey" he yelled, as he would hew to these comparisons.

  • radarbob (unregistered) in reply to foo AKA fooo
    foo AKA fooo:
    Jeremy:
    if (cond)
      ...
    else
      ...
    default
      assert ("should never get here");
    
    if (cond)
      ...
    else
      goto default;
    
    default:
      assert ("should never get here");
    

    FIFY

  • TenshiNo (unregistered) in reply to Adam_Weishaupt

    Believe it or not, I've worked with some developers who might have built this.

  • mbs (unregistered)

    Okay, if this was C, I would probably do something like this:

    int has_vowels(const char *str)
    {
        return (strpbrk(str, "AaEeIiOoUu") != NULL);
    }
    

    But what is a good way of solving this in JAVA? I don’t use this language a lot but now I’m curious. Here’s my try, but regex feels like an overkill for this task:

        private static final Pattern Vowels = Pattern.compile("^.*?[AaEeIiOoUu].*$");
    
        public static boolean hasVowels(String word) {
            return Vowels.matcher(word).matches();
        }
    
  • Derekwaisy (unregistered)
    Comment held for moderation.
  • Jimmyanten (unregistered)

    prednisone 50 mg tablet cost: https://prednisone1st.store/# prednisone ordering online

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

Log In or post as a guest

Replying to comment #:

« Return to Article