• Matteo (unregistered)

    This looks more like C#...

    FRIST!

  • PRER (unregistered)

    FLIRST! I T HINK THIS IS PHUNNEY

  • (cs)

    So, only integers are numeric? So when I count dollars and cents, I'm not using... numbers? Huh?

  • blah (unregistered)

    The uppercase method names gives a clue as to it being C# and not Java.

  • (cs)

    so the real WTF a usual is that people write far too much code to do string parsing, usually because the library doesn't directly support every case you wish to manage.

    Might not be the best way to do these but they probably filled a purpose needed at the time to get up and running fast.

    Putting them into a separate generic place is a good idea, perhaps StringParsingFunctins might be a better one.

    Java was always poor at string parsing unless your string is exactly the "one and only" match for the type.

  • Dave (unregistered)

    It's C#. Main clue being that there's no such type as a "bool" in Java (in Java it's "boolean")

  • Infinite Time and Space (unregistered)

    There is no WTF here. These functions give you flexibility to handle cases that apply to your situation that the built-ins may not have. Putting them in one class supports easy refactoring. Also, this is a common and reasonable solution when the best available programmer is someone unfamiliar with all of the built in functions of a language. We get paid to get a good enough job done as efficiently as possible. Writing the world's greatest code is often contrary to that. The side effect is that experienced programmers often have to go in and clean up someone else's mess to add new features that the original planners could not have possibly foreseen. It is what we are paid to do. Deal with it or pick another career.

  • Some Jerk (unregistered) in reply to Cbuttius
    Cbuttius:
    so the real WTF a usual is that people write far too much code to do string parsing, usually because the library doesn't directly support every case you wish to manage.

    Might not be the best way to do these but they probably filled a purpose needed at the time to get up and running fast.

    Putting them into a separate generic place is a good idea, perhaps StringParsingFunctins might be a better one.

    Java was always poor at string parsing unless your string is exactly the "one and only" match for the type.

    no... TRWTF is that everything he wrote is supported directly by the string library (except that null string thing). The null string thing can be handled like this: var someVal = stringArg ?? ""; basically... this fool needed to look busy so he set about reinventing the wheel day in and day out. I suppose it beats spending all day on wtf.com :p

  • Some Jerk (unregistered) in reply to Some Jerk
    Some Jerk:
    Cbuttius:
    so the real WTF a usual is that people write far too much code to do string parsing, usually because the library doesn't directly support every case you wish to manage.

    Might not be the best way to do these but they probably filled a purpose needed at the time to get up and running fast.

    Putting them into a separate generic place is a good idea, perhaps StringParsingFunctins might be a better one.

    Java was always poor at string parsing unless your string is exactly the "one and only" match for the type.

    no... TRWTF is that everything he wrote is supported directly by the string library (except that null string thing). The null string thing can be handled like this: var someVal = stringArg ?? ""; basically... this fool needed to look busy so he set about reinventing the wheel day in and day out. I suppose it beats spending all day on wtf.com :p

    -- string library = bad choice of words.

    double.TryParse(...) and other such interfaces make adequet substitutions as well.

  • Some Jerk (unregistered) in reply to Infinite Time and Space
    Infinite Time and Space:
    There is no WTF here. These functions give you flexibility to handle cases that apply to your situation that the built-ins may not have. Putting them in one class supports easy refactoring. Also, this is a common and reasonable solution when the best available programmer is someone unfamiliar with all of the built in functions of a language. We get paid to get a good enough job done as efficiently as possible. Writing the world's greatest code is often contrary to that. The side effect is that experienced programmers often have to go in and clean up someone else's mess to add new features that the original planners could not have possibly foreseen. It is what we are paid to do. Deal with it or pick another career.

    True... but implicit with the role of programmer is a subtle expectation of having at least some degree of common sense.

    Captcha: transverbero - a verb that looks one way but goes another.

  • Bob (unregistered) in reply to Infinite Time and Space

    I agree with Mr. Time and Space here. Code monkeys, as a breed, are far too eager to start shooting down everybody else's thinking. I believe it's because a lot of us have insecurities about our own abilities and by shooting first all the time it deflects attention from our own weaknesses and makes us feel better about ourselves. It's the one part of this field that really irks me. It's in other fields, too, but it seems to be rampant around programming in general.

  • Some Jerk (unregistered) in reply to Dave
    Dave:
    It's C#. Main clue being that there's no such type as a "bool" in Java (in Java it's "boolean")

    c/c++ use bool ;P... though member signatures are different.

  • Bob (unregistered) in reply to Some Jerk

    That's exactly what I was talking about in my last post. This person did something slightly different than I would have, therefore they are a complete idiot devoid of any common sense whatsoever. Wow - get over yourself dude.

  • Esse (unregistered)

    I like the fact that -12 somehow isn't numeric.

  • Some Jerk (unregistered) in reply to Bob
    Bob:
    That's exactly what I was talking about in my last post. This person did something slightly different than I would have, therefore they are a complete idiot devoid of any common sense whatsoever. Wow - get over yourself dude.

    you are taking this quite personally. You rename a handful of CLR functions in your past? :p

    So this isn't a WTF like an infinate recursion loop... but there is nothing wrong with laughing at someone for basically renaming library functions or writing inferior ones to use in place of those that are built in.

  • Bill Coleman (unregistered)

    Someone should have taught this guy how to use temporary variables:

    string trimmedValue = value.ToString().Trim();

    But the level of paranoia is really high.

  • Some Jerk (unregistered)

    What I find truly frightening is this

    public static string ReturnEmptyStringIfNullElseValue(string value)

    {
        // here is my null check
        if (value == null)
    
        {
    
            return "";
    
        }
    
        else
    
        {
    

    // MY PARAMETER, which is strongly typed as a string // IS NOT NULL, so now I just need to make sure it is // STILL A STRING! return value.ToString().Trim();

        }
    
    }
    
  • (cs) in reply to Some Jerk
    Some Jerk:
    no... TRWTF is that everything he wrote is supported directly by the string library (except that null string thing). The null string thing can be handled like this: var someVal = stringArg ?? ""; basically... this fool needed to look busy so he set about reinventing the wheel day in and day out. I suppose it beats spending all day on wtf.com :p
    Ah, so that's why, because I'm using an empty-string-instead-of-null method in the Java application I wrote and that I happened to be looking at a few minutes ago. Java can get pedantic with null pointer exceptions, and it doesn't have a similar construct.
  • ullamcorper (unregistered)

    I find it funny how close to python code the method name "ReturnEmptyStringIfNullElseValue" is.

    def ReturnEmptyStringIfNullElseValue(value):
         return "" if not value else value
    
    In: ReturnEmptyStringIfNullElseValue(None)
    Out: ''
    
    In: ReturnEmptyStringIfNullElseValue("value")
    Out: 'value'
  • the beholder (unregistered) in reply to Bob
    Bob:
    I agree with Mr. Time and Space here. Code monkeys, as a breed, are far too eager to start shooting down everybody else's thinking. I believe it's because a lot of us have insecurities about our own abilities and by shooting first all the time it deflects attention from our own weaknesses and makes us feel better about ourselves. It's the one part of this field that really irks me. It's in other fields, too, but it seems to be rampant around programming in general.
    You should abandon programming STAT and enter sociology. That way everyone would be happy: you would be paid to analyze people and we would be subjected to less posts where someone defends a programmer who clearly either didn't know what he was doing or didn't think things through. And also we would only get a socio-anthropological analysis of why we do what we do when we want it.

    And I should become a career counselor :)

  • Spivonious (unregistered)

    I don't see a WTF in the first method. I have one of those myself (in VB.NET, where there is no ?? operator). Of course, you could write it with the ?? operator, but not too many people know about that one.

    edit - I now know that I can use the If() method in those cases. You learn something new everyday.

    As far as the others, what is the built-in function for removing $ and , from strings to get an integer value?

    I'll give you a WTF for the IsNumeric function. If he didn't want to use TryParse, then he could have included the VB library and called VB's old IsNumeric function.

  • (cs) in reply to Spivonious

    The lack of a ternary operator is one of my biggest pet peeves in VB. That and the general lack of operator overloading.

  • Marlon (unregistered)

    UNICORNS!!!!!

    *edit, no this is not spam...

  • Spivonious (unregistered) in reply to Remy Porter
    Remy Porter:
    The lack of a ternary operator is one of my biggest pet peeves in VB. That and the general lack of operator overloading.

    int i = a < b ? 1 : 2; Dim i = If(a < b, 1, 2)

    Public Shared Operator +(lhs As Integer, rhs As Integer) As Integer Return lhs + rhs End Operator

  • (cs) in reply to Spivonious

    If() is computationally the same as the ternary operator, but it is not a ternary operator. The ternary operator is cleaner in terms of syntax, in my opinion.

  • the beholder (unregistered)

    hey, if this is a Remy post were are the HTML comments? Unicorns are not enough, you should now that Remy

  • Not an enterprise code monkey (unregistered)

    You can do this in one line in Haskell

  • (cs) in reply to the beholder

    It's a little hard to insert good HTML comments in a CodeSOD.

  • One Coder, One Cattle Prod (unregistered) in reply to Spivonious

    Seriously? I'm a tester (OK, an SDET) and even I know that C# has a null coalescing operator. Any developer who can't even be bothered to familiarise themselves with simple features of their chosen language needs to get a new job. I hear the helpdesk are hiring.

  • Matt (unregistered)

    maybe string.IsNullOrEmpty() did not occur to him.

  • (cs) in reply to Spivonious
    Spivonious:
    I don't see a WTF in the first method. I have one of those myself (in VB.NET, where there is no ?? operator). Of course, you could write it with the ?? operator, but not too many people know about that one.

    edit - I now know that I can use the If() method in those cases. You learn something new everyday.

    As far as the others, what is the built-in function for removing $ and , from strings to get an integer value?

    I'll give you a WTF for the IsNumeric function. If he didn't want to use TryParse, then he could have included the VB library and called VB's old IsNumeric function.

    There are redundant ToString() calls throughout the code. There's also a fear of having a local copy of the data you're working on.

    The only WTF I see is the duplication of IsNumeric(). Everything else is simply inefficient but unlike what some posters have said it does NOT simply redo the library.

  • Bob (unregistered) in reply to Some Jerk
    Some Jerk:
    Bob:
    That's exactly what I was talking about in my last post. This person did something slightly different than I would have, therefore they are a complete idiot devoid of any common sense whatsoever. Wow - get over yourself dude.

    you are taking this quite personally. You rename a handful of CLR functions in your past? :p

    So this isn't a WTF like an infinate recursion loop... but there is nothing wrong with laughing at someone for basically renaming library functions or writing inferior ones to use in place of those that are built in.

    I'm just saying it would be more productive if people could point out the flaws of others without having to call them idiots or morons. I mean, I could sit here say "you're an idiot because you can't spell the word infinite" but it would be more constructive to stay focused on the correct way of doing it and not wasting time denigrating the person that you are trying to correct. Too many people act as though they have never made a mistake or done something in a less-than-optimal way, which is ridiculous.

  • just me (unregistered) in reply to Bob
    Bob:
    I'm just saying it would be more productive if people could point out the flaws of others without having to call them idiots or morons. I mean, I could sit here say "you're an idiot because you can't spell the word infinite" but it would be more constructive to stay focused on the correct way of doing it and not wasting time denigrating the person that you are trying to correct. Too many people act as though they have *never* made a mistake or done something in a less-than-optimal way, which is ridiculous.

    +1

    btw, how's your son?

  • (cs)

    From an immediate viewpoint the only one that really looks WTF'y is the last one.

    I'm a C++ programmer and don't know C# and how those functions are total rewrites. It's difficult to know exactly what they are doing anyway. What are all these '$' signs doing there? Parsing amounts of money?

    I'm sure the C# library has much better string parsing options than C++ (istringstream, oh dear is that the best we can do? boost::lexical_cast wrapper of that throwing unhelpful exception when it fails..)

    Now let me explain a concept: objects get printed to strings. But strings don't get loaded into empty objects, strings are parsed by factories which create objects. And it isn't a one-to-one relationship in either direction.

    Incidentally the lack of a hexadecimal point is a WTF in C++ and C# although I think C99 supports it.

  • Craig (unregistered)

    By my recollection the TryParse() methods were not introduced until .NET 2.0. For all we know this code was written in .NET 1.0 or 1.1, in which case you pretty much had to roll your own IsNumeric (unless you leveraged the Microsoft.VisualBasic namespace, which I personally preferred not to do).

    The real WTF is that developers never take into account under what circumstances the code was written. Maybe the developer was using an older version, maybe his boss was hounding him to "just get it done."

    There are plenty of things in this business to make fun of, but these examples aren't as egregious as the story makes them out to be.

  • default_ex (unregistered)

    That first function is horrendously over complicated for what it says it does.

    notNullString = ReturnEmptyStringIfNullElseValue(someString);

    notNullString = someString ?? string.Empty;

    Now it might just be because I actually know the language, but I find the second version much more readable.

  • Rob (unregistered) in reply to Remy Porter

    Also, its a function, so both arguments will be evaluated.

    In C# you can write:

    (a == 1) ? b() : c();

    In VB

    IIf(a = 1, b(), c())

    will call both b() and c(), but only return one result!

  • Tuka (unregistered)

    The given functions are not perfect. But there is no WTF. The writer of that code might lack experience or tuition. Anyway, the code shall work, is readable and not horrible inefficient.

    Since that the real WTF is the fellow 'Ben'. His mention those examples as WTF is an proof that Ben is a arrogant, autocratic goof.

    A self-opinionated mind is one of the saves ways into programers hell.

  • Wonk (unregistered) in reply to just me
    just me:
    Bob:
    I'm just saying it would be more productive if people could point out the flaws of others without having to call them idiots or morons. I mean, I could sit here say "you're an idiot because you can't spell the word infinite" but it would be more constructive to stay focused on the correct way of doing it and not wasting time denigrating the person that you are trying to correct. Too many people act as though they have *never* made a mistake or done something in a less-than-optimal way, which is ridiculous.

    +1

    btw, how's your son?

    I'm sure it's no laughing matter.

  • Your Name (unregistered)

    Java/C# With First Letter Of Function Capatalized. Twitch.

    NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOoooooooooooooooooooooooooooooo.............

  • (cs)

    Ok, an obvious WTF is calling value.ToString() when value is already a string. I assume that all classes inherit from Object() and must have a ToString() method so string also has one, which probably just is implemented as "return this;"

    It is quite common in C++ too to have a template to convert things to string and then provide an overload / specialization for strings. At least in C# you don't have the WTF'ery of having to deal with two types of character that might form a string.

    Incidentally in C++ if you do this

    template< typename T >
    T parse( std::string const& str )
    {
       std::istringstream iss( str );
       T t;
       iss >> t; // yeah handle errors etc.
       return t;
    }
    

    It is not just inefficient for T=std::string, it doesn't work properly..

    std::string hw( "Hello world" );
    std::string parsed = parse<std::string>(hw);
    

    and parsed will be just "Hello"

    Doing this for a large array of ints is bad too in that you create a stringbuf for every single one and don't reuse it.

  • pantsman (unregistered) in reply to default_ex
    default_ex:
    notNullString = ReturnEmptyStringIfNullElseValue(someString);

    notNullString = someString ?? string.Empty;

    What if this code was written before nullable types were added to the language?

  • nisl (unregistered) in reply to ullamcorper
    ullamcorper:
    I find it funny how close to python code the method name "ReturnEmptyStringIfNullElseValue" is.
    def ReturnEmptyStringIfNullElseValue(value):
         return "" if not value else value
    
    In: ReturnEmptyStringIfNullElseValue(None)
    Out: ''
    
    In: ReturnEmptyStringIfNullElseValue("value")
    Out: 'value'

    It's better not to program than to program in that jiberish.

  • Some Jerk (unregistered) in reply to Bob
    Bob:
    Some Jerk:
    Bob:
    That's exactly what I was talking about in my last post. This person did something slightly different than I would have, therefore they are a complete idiot devoid of any common sense whatsoever. Wow - get over yourself dude.

    you are taking this quite personally. You rename a handful of CLR functions in your past? :p

    So this isn't a WTF like an infinate recursion loop... but there is nothing wrong with laughing at someone for basically renaming library functions or writing inferior ones to use in place of those that are built in.

    I'm just saying it would be more productive if people could point out the flaws of others without having to call them idiots or morons. I mean, I could sit here say "you're an idiot because you can't spell the word infinite" but it would be more constructive to stay focused on the correct way of doing it and not wasting time denigrating the person that you are trying to correct. Too many people act as though they have never made a mistake or done something in a less-than-optimal way, which is ridiculous.

    Obviously. And I enjoy very much ... mocking my own stupidity every opportunity I get. Spelling is usually my problem however... and it has lead to some rather funny situations involving application wide updates and renames. Flatulantly for me... Microsoft added some safeguards for just such an eventuality.

    I suppose I don't remember calling anyone an idiot on this thread however.

    Someone wrote that the user was not substituting pre-existing functionality... and I argue that every method was a substitution of pre-existing syntax and/or built in library methods. So hurry up and (CAPTCHA: AUGUE) with me.

  • nisl (unregistered) in reply to One Coder, One Cattle Prod
    One Coder:
    Seriously? I'm a tester (OK, an SDET) and even I know that C# has a null coalescing operator. Any developer who can't even be bothered to familiarise themselves with simple features of their chosen language needs to get a new job. I hear the helpdesk are hiring.

    Usually bozos like that are not qualified for ANY IT job.

  • (cs) in reply to Craig
    Craig:
    By my recollection the TryParse() methods were not introduced until .NET 2.0. For all we know this code was written in .NET 1.0 or 1.1, in which case you pretty much had to roll your own IsNumeric (unless you leveraged the Microsoft.VisualBasic namespace, which I personally preferred not to do).

    The real WTF is that developers never take into account under what circumstances the code was written. Maybe the developer was using an older version, maybe his boss was hounding him to "just get it done."

    There are plenty of things in this business to make fun of, but these examples aren't as egregious as the story makes them out to be.

    Please use the established meme: I don't see what's wrong with this code! Does anyone of you bitches know the specs?

  • C-Derb (unregistered) in reply to Cbuttius
    Cbuttius:
    Ok, an obvious WTF is calling value.ToString() when value is already a string.
    +100 I get that sometimes you may write code only to realize later that there is something similar built into the language. And I agree that all we are presented with is the code and no context to when it was written and what was built into the framework at the time.

    But calling string.ToString() is indefensible. Whiskey. Tango. Foxtrot.

  • nisl (unregistered) in reply to Craig
    Craig:
    By my recollection the TryParse() methods were not introduced until .NET 2.0. For all we know this code was written in .NET 1.0 or 1.1, in which case you pretty much had to roll your own IsNumeric (unless you leveraged the Microsoft.VisualBasic namespace, which I personally preferred not to do).

    The real WTF is that developers never take into account under what circumstances the code was written. Maybe the developer was using an older version, maybe his boss was hounding him to "just get it done."

    There are plenty of things in this business to make fun of, but these examples aren't as egregious as the story makes them out to be.

    He was using TryParse methods, therefore he was using at least 2.0.

    I can see entering .NET using VB, but sticking with it after 10 fucking years of development is just plain stupid - even if the company can't or doesn't allow the switch (move the fuck on). If you're still with VB.NET, you are a moron and incompetent programmer by definition.

    "Just get it done" attitude would need to result in inline "if null set "" else set value" pattern - versus writing some confusingly named and what-the-fuck-that-this-function-really-do-let-me-look-it-up-every-time-cause-it-is-impossible-to-remember-ever functions.

    What other excuses can you think of?

  • Dave2 (seriously) (unregistered) in reply to Some Jerk

    Also, the "out" keyword is only used in C# I believe. Not java or c/c++.

  • (cs) in reply to Wonk
    Wonk:
    just me:
    Bob:
    ...

    +1

    btw, how's your son?

    I'm sure it's no laughing matter.

    Wrong!

    Stated it before and will state it again: Bob and i are not related!

    Neither am i his son nor is he my uncle!

Leave a comment on “Common Functions, not Common Sense”

Log In or post as a guest

Replying to comment #:

« Return to Article