• SatanClaus (unregistered)

    When I was new to Java, I made a handful of mistakes like this. The one that stands out is that I didn't know regular expressions were built into Java.

  • (cs) in reply to SuperAnalyst
    SuperAnalyst:
    but if it works, it works.
    In basketball, there's such a thing as a good shot that misses and a bad shot that goes in. The same is true of programming. Just because it seems to work now doesn't mean it is good enough. The complexity could result in bugs being introduced during maintenance, the inefficiency could lead to performance problems, etc.
  • mara (unregistered) in reply to Anon
    Anon:
    FYI to all the java programmers providing solutions, the method is
    split
    and not
    Split
    and on top of that it doesn't take character array as an argument.
    To all the people who don't look at the code: It is "string" not "String" and the methods start with an upper case letter. It is very likely that this is C# not Java.
  • mara (unregistered) in reply to Tim
    Tim:
    I'm pretty sure this is C# code, not Java.

    I don't know C# - can you really call a function that takes a Char[] by passing the chars as separate parameters?

    How does it deal with this:

    void func(Char[] foo); void func(Char a, Char b);

    ...

    func('a', 'b');

    My guess, same way Varargs in Java is done. The best match wins. So Char, Char not Char[].

  • Daniel (unregistered)

    Reminds me of the time where I had to write something very closely resembling an XML-Parser, because the MS-Shrinkheads simply don't expose the stream position of found artifacts in their XmlReader class.

    What my predecessor did with this particular problem would make a good WTF though, except that it's much too large to submit.

  • (cs)

    C# has a params keyword for variadic functions...

    public void MyMethod(params char[] chars)
    {
        // DO STUFF
    }
    
    public void DemoMyMethod()
    {
        char[] foo = new char[5];
    
        this.MyMethod(foo); // Legal
        this.MyMethod('a', 'b', 'c', 'd'); // Legal
    }
  • The Gloved One (unregistered) in reply to Tim
    Tim:
    How does it deal with this:

    void func(Char[] foo); void func(Char a, Char b);

    ...

    func('a', 'b');

    string years = "40,000"; func(years.ToCharArray());

  • zoips (unregistered)

    How do people keep confusing Java and C#? Don't things like string as a type, properties (such as emails.Length, list.Count), and upper-case method names seem like a clue? I mean, sure, they're a little more subtle than struct and delegate, but come on...

  • RBoy (unregistered) in reply to monkeyPushButton
    monkeyPushButton:
    SCB:
    Bobbo:
    sagaciter (rocking the captchah:
    • the a st**pid fail-training train

    The what?

    stoopid

    Thanks for making this thread not work safe.

    The **'s, they do nothing

  • Raymond Chen (unregistered)

    Note that this code differs from Split in its treatment of consecutive delimiters.

  • FragFrog (unregistered) in reply to SatanClaus
    SatanClaus:
    When I was new to Java, I made a handful of mistakes like this. The one that stands out is that I didn't know regular expressions were built into Java.

    There is a famous quote that applies here I think:

    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems.

    In my opinion, a good programmer distanciates himself from a bad programmer by knowing not a way to do something, but the best way to do something. Unfortunately that only comes over time, if at that. A most likely rookie WTF today :)

  • (cs) in reply to SCB
    SCB:
    Bobbo:
    sagaciter (rocking the captchah:
    • the a st**pid fail-training train
    The what?
    stoopid
    To be grammatically correct, the variant double-o spelling should be accompanied by a switch from "d" to "t", as follows:

    stoopit

  • (cs) in reply to NoXzema
    Pim:
    If, at every routine I'm writing, I were to think, hey, maybe there's an API call somewhere that does the same thing; why don't I just launch a quick internet search and spend the afternoon surfing across msdn.microsoft.com, my programs would take much longer to write, even if they would end up marginally smaller.

    I wonder how quickly could you code something to replace classes like WebClient or GZIPStream.

  • (cs)

    Surprisingly hard to parse email addresses. Take the following example for validating all possible permutations allowed by RFC 2822:

    /*
     * @(#) EmailAddresses.java
     *
     * Copyright (C) 2001, All Rights Reserved
     */
    
    package net.chriswareham.util;
    
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    /**
     * Utility methods for validating email addresses.
     *
     * @author Chris Wareham
     */
    public final class EmailAddresses {
        /** Regular expression that matches one or more ASCII characters. */
        private static final String ASCII_REGEX = "\\p{ASCII}+";
        /** Regular expression that matches two or more tokens separated by an 'at' character. */
        private static final String EMAIL_REGEX = "\\s*?(.+)@(.+?)\\s*";
    
        /** Regular expression that matches an IP address enclosed in square brackets. */
        private static final String DOMAIN_IP_REGEX = "\\[(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\]";
        /** Regular expression that matches a sub domain. */
        private static final String DOMAIN_SUB_REGEX = "\\p{Alnum}(?>[\\p{Alnum}-]*\\p{Alnum})*";
        /** Regular expression that matches a top level domain. */
        private static final String DOMAIN_TLD_REGEX = "\\p{Alpha}{2,6}";
        /** Regular expression that matches a domain name. */
        private static final String DOMAIN_NAME_REGEX = "(?:" + DOMAIN_SUB_REGEX + "\\.)*" + "(" + DOMAIN_TLD_REGEX + ")";
    
        /** Regular expression that matches special characters in a user name. */
        private static final String SPECIAL_CHARS = "\\p{Cntrl}\\(\\)<>@,;:'\\\\\\\"\\.\\[\\]";
        /** Regular expression that matches valid charactsers in a user name. */
        private static final String VALID_CHARS = "[^\\s" + SPECIAL_CHARS + "]";
        /** Regular expression that matches quoted characters in a username. */
        private static final String QUOTED_CHARS = "(\"[^\"]*\")";
        /** Regular expression that matches a word component in a user name. */
        private static final String WORD = "((" + VALID_CHARS + "|')+|" + QUOTED_CHARS + ")";
        /** Regular expression that matches a user name. */
        private static final String USER_REGEX = "\\s*" + WORD + "(\\." + WORD + ")*";
    
        /** Pattern that matches one or more ASCII characters. */
        private static final Pattern ASCII_PATTERN = Pattern.compile(ASCII_REGEX);
        /** Pattern that matches two or more tokens separated by an 'at' character. */
        private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX);
        /** Pattern that matches an IP address enclosed in square brackets. */
        private static final Pattern DOMAIN_IP_PATTERN = Pattern.compile(DOMAIN_IP_REGEX);
        /** Pattern that matches a domain name. */
        private static final Pattern DOMAIN_NAME_PATTERN = Pattern.compile(DOMAIN_NAME_REGEX);
        /** Pattern that matches a user name. */
        private static final Pattern USER_PATTERN = Pattern.compile(USER_REGEX);
    
        /**
         * Utility class - no public constructor.
         */
        private EmailAddresses() {
            // empty
        }
    
        /**
         * Return whether a string is a valid email address. A valid email address
         * must conform to the rules for remote addresses as specified in RFC 2822.
         *
         * @param emailAddress the string to validate
         * @return whether the string is a valid email address
         */
        public static boolean isEmailAddress(final String emailAddress) {
            if (emailAddress.endsWith(".")) {
                return false;
            }
    
            if (!ASCII_PATTERN.matcher(emailAddress).matches()) {
                return false;
            }
    
            Matcher matcher = EMAIL_PATTERN.matcher(emailAddress);
    
            if (!matcher.matches()) {
                return false;
            }
    
            if (!isValidUser(matcher.group(1))) {
                return false;
            }
    
            if (!isValidDomain(matcher.group(2))) {
                return false;
            }
    
            return true;
        }
    
        /**
         * Return whether the domain component of an email address is valid.
         *
         * @param domain the domain to validate
         * @return whether the domain is valid
         */
        private static boolean isValidDomain(final String domain) {
            Matcher matcher = DOMAIN_IP_PATTERN.matcher(domain);
    
            if (!matcher.matches()) {
                return DOMAIN_NAME_PATTERN.matcher(domain).matches();
            }
    
            for (int i = 1; i < 5; ++i) {
                String ipSegment = matcher.group(i);
    
                int iIpSegment = 0;
    
                try {
                    iIpSegment = Integer.parseInt(ipSegment);
                } catch (NumberFormatException exception) {
                    return false;
                }
    
                if (iIpSegment > 255) {
                    return false;
                }
            }
    
            return true;
        }
    
        /**
         * Return whether the user component of an email address is valid.
         *
         * @param user the user to validate
         * @return whether the user is valid
         */
        private static boolean isValidUser(final String user) {
            return USER_PATTERN.matcher(user).matches();
        }
    }
    
  • (cs) in reply to Mr B
    Edward Royce:
    Did you know that the "acnestis" is the part of the back that's impossible to scratch?

    For quadrupeds, yes. I don't think the term applies to humans viz :

    "That part of the spine which reaches from betwixt the shoulder blades to the loins. This name seems only applicable to quadrupeds, because they cannot reach it to scratch." From "The London Medical Dictionary"

    Probably the sort of subtle mistake one would make coding one's own version of a standard library function.

  • Anon (unregistered) in reply to Raymond Chen
    Raymond Chen:
    Note that this code differs from Split in its treatment of consecutive delimiters.

    String.Split has several overrides that take StringSplitOptions as an argument which alters the way it handles consecutive delimiters.

  • Wizard Stan (unregistered) in reply to Lol Lolovici
    Lol Lolovici:
    Mr B:
    Did you know that the "acnestis" is the part of the back that's impossible to scratch?

    No? I didn't either until I looked it up - but I managed before by saying "that bit just behind my shoulder blades that I can't scratch". OK it was a bit long winded, but in many ways it's easier to communicate with people the long-winded way, rather than using an obscure word which you'd probably end up having to explain the meaning of anyway.

    :)

    So are you saying that it's easier when you talk to people to say "Moses did that action that applied to an object creates several subparts of that object to the waters" instead of "Moses split the waters"?

    I'm pretty sure he's making the case that there are instances where using the description is faster, easier, and better than the simple word itself. Whether "split" is one of those instances was not part of his argument.

    Honestly, for a bunch of people that occasionally call themselves programmers, there's a lot of closed minded attitude going around. And it's not just you and your post; I've noticed a disturbing trend the last few weeks of posts that take someones argument-via-analogy and interpret it literally, in an apparent attempt to counter that argument, instead of generalizing said analogy to understand other instances where it may be true.

  • (cs) in reply to Mr B
    Mr B:
    Edward Royce:
    Rollerscopter:
    Yeah right, cause string.Split() is an obscure, rarely-used method.

    It's a funny thing.

    When I was a very young kid and having just learned the basics of English, got adopted into an American family, I spent weeks reading dictionaries from cover to cover so I could have a better understanding of the language.

    Yet there are professional programmers who learn the syntax of a language but don't bother furthering their understanding of all the functions and objects available for that language.

    strange.

    So how many of the 540,000 words in the English language do you know?

    Did you know that the "acnestis" is the part of the back that's impossible to scratch?

    No? I didn't either until I looked it up - but I managed before by saying "that bit just behind my shoulder blades that I can't scratch". OK it was a bit long winded, but in many ways it's easier to communicate with people the long-winded way, rather than using an obscure word which you'd probably end up having to explain the meaning of anyway.

    :)

    I can scratch any part of my back with either hand... the wonders of being slightly double jointed.

    Also - isn't email validation a fairly well known, overly solved problem? I hate it when people go OH BUT MAYBE HE DOESN'T KNOW ALL THE LIBRARY FUNCTIONS... yeah, but the most common ones should be easy to find. And even implemented correctly.

  • Duke of New York (unregistered) in reply to java.lang.Chris;
    java.lang.Chris;:
    Surprisingly hard to parse email addresses. Take the following example for validating all possible permutations allowed by RFC 2822:
    But...couldn't you just have easily used a link?
  • (cs) in reply to FragFrog
    FragFrog:
    In my opinion, a good programmer distanciates himself from a bad programmer by knowing not a way to do something, but the best way to do something.

    "Distanciates"? I like that. An instantiation of the act of distancing yourself, or something.

    I'm goingtolunchiating now.

  • Lincoln (unregistered) in reply to Bobbo

    stbuttpid

  • (cs) in reply to Bart
    Bart:
    A "decent subset" of the Java library should include String.split, or it is not "decent".

    Learning all of the libraries for a language such as Java is not feasible; however, any developer should imho try to constantly expand the tools (i.e. the "decent subset of calls" ) at his disposal. If what you are trying to code seems like something that should be in a library, chances are it is in the library, but you just did not find it yet.

    You say that, but I notice that you haven't pointed out that none of the code snippets for splitting strings yet given work in Java. (Not too surprising, given that the code in the article isn't Java, but...) The only String.split methods in the Java standard libraries were introduced in 1.4 and use a String representing a regex to define the tokens around which to split.

  • Franz Kafka (unregistered) in reply to Mr B
    Mr B:
    Edward Royce:
    Rollerscopter:
    Yeah right, cause string.Split() is an obscure, rarely-used method.

    It's a funny thing.

    When I was a very young kid and having just learned the basics of English, got adopted into an American family, I spent weeks reading dictionaries from cover to cover so I could have a better understanding of the language.

    Yet there are professional programmers who learn the syntax of a language but don't bother furthering their understanding of all the functions and objects available for that language.

    strange.

    So how many of the 540,000 words in the English language do you know?

    Did you know that the "acnestis" is the part of the back that's impossible to scratch?

    No? I didn't either until I looked it up - but I managed before by saying "that bit just behind my shoulder blades that I can't scratch". OK it was a bit long winded, but in many ways it's easier to communicate with people the long-winded way, rather than using an obscure word which you'd probably end up having to explain the meaning of anyway.

    :)

    String.split is more like one of the obscurer meanings of 'take'. If you've spent any time in the language, you should have a really good knowledge of java.io, java.lang, and java.util.

  • SomeCoder (unregistered)

    Gloves.

    That is all.

  • Duke of New York (unregistered) in reply to Abraham Maslow
    Abraham Maslow:
    To the man who only has a hammer, everything he encounters begins to look like a nail.
    ... and ends up being a thumb.
  • wat (unregistered) in reply to sagaciter (rocking the captchah, rocking the captchah...)
    sagaciter (rocking the captchah:
    This is typical of Java mistraining: - some manager thaught that this new-fangled java thing is cool, let's train the dev's on it, etc. etc. - the a st**pid fail-training train comes, and gives the course on java as a _language_ alone (look ma, garbage collection, weak references, whohoo !), when actually knowing what's inside the java libraries should be 4/5 of it. (sigh...) been there, seen that, should have created a tee-shirt, would be rich by now.

    Not that it makes any real difference, but the language in question is C#.

  • Jay (unregistered) in reply to Renan "C#" Sousa
    Renan "C#" Sousa:
    Pim:
    If, at every routine I'm writing, I were to think, hey, maybe there's an API call somewhere that does the same thing; why don't I just launch a quick internet search and spend the afternoon surfing across msdn.microsoft.com, my programs would take much longer to write, even if they would end up marginally smaller.

    I wonder how quickly could you code something to replace classes like WebClient or GZIPStream.

    Suppose I wasn't aware of Java's Math.max function, and so instead of writing

    bigger=Math.max(a,b);

    I wrote

    bigger=a>=b ? a : b;

    Surely it would take me far longer to do the research to find the library function: We'd have to assume here that if I'm unaware of the function, I don't necessarily know that it's in the "Math" class or what it's called. Any competent programmer reading the code would surely understand it just as well as he would the function call. Better, perhaps, because maybe the reader doesn't know the function call and would have to look it up.

    On the other hand, the first time I had to do DES and MD5 encryption, it was obvious that the research required to find library functions to do this would very likely be less than the research to find the rules so that I could write my own functions.

    Seems to me it's like the classic manufacturing "make or buy" decision: how much work is it to build it myself versus how much work to find something already built by someone else and learn to use it.

    By the way, I've seen plenty of cases where someone took the "obviously I should use the existing library routine rather than writing it myself" logic to the point that he writes more code to wrap around the library call than it would have taken him to just do what he needed to do.

  • Duke of New York (unregistered)

    By ignoring the language in the post (which has usually been altered to protect the guilty anyway), you can spin this as an indictment of any language you want to grumble about.

    "This is typical of idiot C programmers who have never used a language that comes with decent libraries and string support."

    "This is typical of idiot Perl developers who pride themselves on being able to do things more than one way."

    Truth is, it's just typical of programmers under pressure to get something working.

  • Some Guru (unregistered) in reply to abx
    abx:
    Tim:
    I'm pretty sure this is C# code, not Java.

    I don't know C# - can you really call a function that takes a Char[] by passing the chars as separate parameters?

    How does it deal with this:

    void func(Char[] foo); void func(Char a, Char b);

    ...

    func('a', 'b');

    in C#, if the signature is: func(params char[] foo); the params keyword allows you to invoke it by passing the chars as separate parameters, and you treat it as an array inside the function.

    func('a','b'); will invoke the signature that explicitly matches your call, but func('a','b','c') will invoke the overload with the params keyword.

    Sweet, so I can add a method:

    void func(Char a, Char b, Char c);

    And change the semantics of existing method calls, including subclasses. Brillant!

  • bramster (unregistered) in reply to Dr. Evil
    Dr. Evil:
    Mr B:
    Edward Royce:
    Rollerscopter:
    Yeah right, cause string.Split() is an obscure, rarely-used method.

    It's a funny thing.

    When I was a very young kid and having just learned the basics of English, got adopted into an American family, I spent weeks reading dictionaries from cover to cover so I could have a better understanding of the language.

    Yet there are professional programmers who learn the syntax of a language but don't bother furthering their understanding of all the functions and objects available for that language.

    strange.

    So how many of the 540,000 words in the English language do you know?

    Did you know that the "acnestis" is the part of the back that's impossible to scratch?

    No? I didn't either until I looked it up - but I managed before by saying "that bit just behind my shoulder blades that I can't scratch". OK it was a bit long winded, but in many ways it's easier to communicate with people the long-winded way, rather than using an obscure word which you'd probably end up having to explain the meaning of anyway.

    :)

    Maybe so, but string.Split() is the nose on your face, not the acnestis on your back :)

    I don't recall seeing string.split in K&R. . .

  • whatever (unregistered)

    I have to poop...

  • (cs) in reply to Anonymous
    Anonymous:
    I was thinking, hey I know the guy who wrote this but then I realized it was missing his trademark ... if (doneCur == true)
    I often do that for false, because I feel ! isn't verbose enough, and it doesn't sit right if it's a double negative.

    if(!notDoneYet) { ... } if(notDoneYet == false) { ... } if(doneNow) { ... }

    But I try to pick more descriptive names than that.

    if(foundSomeMatches) { ... } else { ... }

    if(doneSplittingStuff) { ... }

    That way the code is legible and understandable without tons and tons of comments.

  • the real whatever (unregistered) in reply to whatever
    LightStyx:
    I have to poop...

    Come on now LightStyx, put some effort into it.

    What you should have done is sit there clicking TDWTF endlessly until you can post a FIRST POST in my name, and then lambaste yourself for it.

    Or you could insult OTHER users in my anonymous persona. Boy wouldn't that be fun! Ha ha!

    'Cuz, you know, I have a lot invested in this anonymous, unregistered username.

  • dwaz (unregistered) in reply to Some Guru
    Some Guru:
    Sweet, so I can add a method:
    void func(Char a, Char b, Char c);

    And change the semantics of existing method calls, including subclasses. Brillant!

    Yes, but the same could happen anyway, so what's your point?

    If you have a function:

    void Foo(object o)

    Which someone calls as:

    Foo("some string");

    And you later add:

    void Foo(string s)

    Then the call changes as well (after a recompile at least, already compiled code would still be bound to Foo(object)).

  • awfwefewa (unregistered) in reply to Mr B
    Mr B:
    Did you know that the "acnestis" is the part of the back that's impossible to scratch?
    Acne on the tits is tragic.
  • (cs) in reply to awfwefewa
    awfwefewa:
    Mr B:
    Did you know that the "acnestis" is the part of the back that's impossible to scratch?
    Acne on the tits is tragic.

    Make this a featured blue comment please! It's already a little bit blue, so we're halfway there...

  • (cs) in reply to Some Guru
    Some Guru:
    Sweet, so I can add a method:
    void func(Char a, Char b, Char c);
    And change the semantics of existing method calls, including subclasses. Brillant!
    Yes, but only with a recompile. The compiler converts the type signature to a specific set of argument types for you. IIRC it also includes the return type and any exception types too, at least with Java, and I think C# is the same this way. Things might be a bit crazy, but they're not totally batshit.

    If you change the semantics of a method out from under the feet of subclasses then yes, you can get some very odd errors. This is a well-known issue and the usual response is “if it is a problem, you've got a developer who needs introducing to the LART.” Don't Do That. (I've dropped libraries entirely when the developer pulled that sort of game on me without adequate warning. Life's too short for putting up with silliness without good reason.)

  • Americium (unregistered) in reply to Pim
    Pim:
    Sure, it's a WTF. I'm not gonna say it's not a WTF.

    But these modern day compiler libraries are so incredibly large, it's impossible to know, and understand, and be able to use, every single call that's included. It would take years, if not decades, for a programmer to get to know all the ins and outs of a given library. And then in the end, when he knows everything, he'll find that his knowledge is outdated and there are newer versions of the libraries with different functionalities.

    So the best you can aspire to is to learn a decent subset of the calls at your disposal, and to use those to the best of your abilities.

    If, at every routine I'm writing, I were to think, hey, maybe there's an API call somewhere that does the same thing; why don't I just launch a quick internet search and spend the afternoon surfing across msdn.microsoft.com, my programs would take much longer to write, even if they would end up marginally smaller.

    This is a simple string tokenizer, not some fancy API call! Splitting strings on characters is so old that COBOL has built-in routines for it.

    The fact that the strings are e-mail addresses obfuscates the task. I bet the programmer has several string tokenizer procedures, rather than one re-used subroutine that he wrote.

    It's possible to write your own code AND keep it small & organized.

  • diaphanein (unregistered) in reply to Renan "C#" Sousa
    Renan "C#" Sousa:
    Pim:
    If, at every routine I'm writing, I were to think, hey, maybe there's an API call somewhere that does the same thing; why don't I just launch a quick internet search and spend the afternoon surfing across msdn.microsoft.com, my programs would take much longer to write, even if they would end up marginally smaller.

    I wonder how quickly could you code something to replace classes like WebClient or GZIPStream.

    I have written a GZipStream in C# before. In my defense, there wasn't one in the std lib at the time, and there were no open source versions with acceptable licenses. This was also in the 1.0/1.1 days, so its been a few years. I recall it as being a fun, but multiday, project.

  • hey persto! (unregistered) in reply to sagaciter (rocking the captchah, rocking the captchah...)
    sagaciter (rocking the captchah:
    This is typical of Java mistraining: - some manager thaught that this new-fangled java thing is cool, let's train the dev's on it, etc. etc. - the a st**pid fail-training train comes, and gives the course on java as a _language_ alone (look ma, garbage collection, weak references, whohoo !), when actually knowing what's inside the java libraries should be 4/5 of it. (sigh...) been there, seen that, should have created a tee-shirt, would be rich by now.

    This is typical of TDWTF posters. Not enough knowledge, too much ego. The language is clearly C# and not Java. Java does not have properties, String.Length is C#, the naming conventions are C#, List is an interface in Java, "string" is not a java type, "String" is.

    Ok, now that we have that out of the way, knowing how libraries are implemented is very, very unimportant. Knowing their use is important, knowing their expense is slightly less important and not much else matters. Why should anyone spend time understanding the implementation of library functions when there is real productive work to be done?

  • 50% Opacity (unregistered) in reply to BikeHelmet
    BikeHelmet:
    I often do that for false, because I feel ! isn't verbose enough, and it doesn't sit right if it's a double negative.

    if(!notDoneYet) { ... } if(notDoneYet == false) { ... }

    Maybe it's just me, but I find the double negative in "notNotDoneYet" easier to parse than "notDoneYet == false", the latter requiring me to actually think about what it's supposed to mean. "!not" easily cancels itself out while reading, "not == false" doesn't IMHO.

    Double negatives shouldn't not be avoided anyway, as you didn't omit to point out yourself.

  • Anonymous Coward (unregistered)

    I read somewhere that this is 'See Pound" and not yaba, so there is no library from where to find a book about it!

    Captcha: luctus - A lactose derivative?

    (See I've only been reading TDWTF for a few months and already learned the slangs... BTW First.... of the third page... or not!)

  • ted (unregistered) in reply to ounos

    I always love to read the comments on TDWTF! (okay, the articles too...)

    The first time I saw those entries containing "grammar Nazi", etc. it looked a little scary to me (as a German): "Uh oh - bad word detected - how can they write that... :-("

    But it is indeed really funny to read stuff like "Fuhrer" knowing that the guys writing it don't have the "ü"-Key on their keyboards... :-) Looks just... strange...

    Maybe you guys could use "ue" instead - "Fuehrer" would look a lot more authentic...

  • drobnox (unregistered) in reply to Pim
    If, at every routine I'm writing, I were to think, hey, maybe there's an API call somewhere that does the same thing; why don't I just launch a quick internet search and spend the afternoon surfing across msdn.microsoft.com, my programs would take much longer to write, even if they would end up marginally smaller.
    You, sir or madame, are a fool, who must not be able to remember the things they looked up at earlier times.

    I just spent two weeks trying to do something which wound up being solved by one line of code, which I found on stack overflow. If your homegrown solution gets really really complicated, and the problem you're trying to solve ISN'T complicated. throw it out and google harder. Someone's already done it, more than likely. Aspire to egoless programming.

  • (cs) in reply to 50% Opacity
    50% Opacity:

    Maybe it's just me, but I find the double negative in "notNotDoneYet" easier to parse than "notDoneYet == false", the latter requiring me to actually think about what it's supposed to mean. "!not" easily cancels itself out while reading, "not == false" doesn't IMHO.

    Double negatives shouldn't not be avoided anyway, as you didn't omit to point out yourself.

    Ugh. This is why you always use positive logic. Solve the problem by just using:

    while(true == keepGoing) {...}

    (Note 1: while(keepGoing) doesn't work if you have systems for which boolean 'true' and 'false' values are both nonzero, or if you care that you actually have 'true' and not some corrupt nonzero value. Yes, such systems exist and are more common than you'd think. And remember, 'corrupt' doesn't mean just 'bad memory', it can mean 'buffer overflow' or 'virus' as well.)

    (Note 2: rvalues on the left of '==' is just a good idea, and once you get used to it, the strangeness goes away.)

    (Note 3: Yes, I'm an embedded systems programmer. I wish desktop programmers had the same coding standards as embedded. Oh, and by 'embedded' I mean things whose main function is not computing but use computer control. So I'm not talking about your cell phone or portable media device.)

    (Note 4: Yes, I'm opinionated and passionate about this particular subject field!)

  • DeutscherInJapan (unregistered) in reply to ted
    ted:
    I always love to read the comments on TDWTF! (okay, the articles too...)

    The first time I saw those entries containing "grammar Nazi", etc. it looked a little scary to me (as a German): "Uh oh - bad word detected - how can they write that... :-("

    But it is indeed really funny to read stuff like "Fuhrer" knowing that the guys writing it don't have the "ü"-Key on their keyboards... :-) Looks just... strange...

    Maybe you guys could use "ue" instead - "Fuehrer" would look a lot more authentic...

    Welcome to the Intarwebs. You realize you just meta grammar nazi'd somebody, right? Way to improve the stereotype. ;-P

  • Myrmidon (unregistered) in reply to Edward Royce
    Edward Royce:
    dpm:
    You gol-danged whipper-snapper kids and your uppity "methods" should shut up and learn the REAL way to code, like we did back in the day! Ha, "split", you're just begging for trouble by letting some fancy LIBRARY routine do the work for you, ya slacker! How do you know it will work right unless you write the code yourself?? Huh?? Got no answer for that, do you, Mister Smarty-Pants!

    Get off my lawn!!

    FAIL! The correct answer is "You damn kids - get off my LAN!"

    Captcha 'Feugiat' - when Feng Shui meets Italian auto design.

  • Mike T (unregistered) in reply to monkeyPushButton

    Thanks for making this work not thread safe (captcha: commoveo - is that laton for combover?)

  • Mike T (unregistered) in reply to monkeyPushButton
    monkeyPushButton:
    SCB:
    Bobbo:
    sagaciter (rocking the captchah:
    - the a st**pid fail-training train
    The what?
    stoopid
    Thanks for making this thread not work safe.
    Thanks for making this work not thread safe (captcha: commoveo - is that latin for combover?)
  • mabinogi (unregistered) in reply to too_many_usernames
    too_many_usernames:
    (Note 1: while(keepGoing) doesn't work if you have systems for which boolean 'true' and 'false' values are both nonzero, or if you care that you actually have 'true' and not some corrupt nonzero value. Yes, such systems exist and are more common than you'd think. And remember, 'corrupt' doesn't mean just 'bad memory', it can mean 'buffer overflow' or 'virus' as well.)

    (Note 2: rvalues on the left of '==' is just a good idea, and once you get used to it, the strangeness goes away.)

    (Note 3: Yes, I'm an embedded systems programmer. I wish desktop programmers had the same coding standards as embedded. Oh, and by 'embedded' I mean things whose main function is not computing but use computer control. So I'm not talking about your cell phone or portable media device.)

    (Note 4: Yes, I'm opinionated and passionate about this particular subject field!)

    If you're using any language created in the last 20 years, and even most of those created in lifetime of computing, while(keepGoing) would be exactly the right thing to do. Even in C, it's the correct thing to do. If the value can be corrupt, it can be corrupt and equal to true too. Once you've got corrupt memory you're screwed anyway, and no amount of "I'm more clever than you" programming will solve it.

    If your compiler doesn't warn you about using assignment as an equality operator, then get a better compiler - or alternatively, use a language with native boolean type.

    Your advice may or may not make sense for embedded programming (and I personally don't think it really does), but it definitely doesn't make sense for the programming that 99% of people are going to do. If that's representative of embeded programming standards, then the rest of us are very well off without them, thank you very much.

Leave a comment on “The Complicator's Email Address Parser”

Log In or post as a guest

Replying to comment #:

« Return to Article