• myName (unregistered)

    He didn't use something that was introduced after he wrote the program - isn't he a fool.

    Seriously, give use the date the original was written when you're posting WTFs like this.

  • (cs)

    To all of you defending this code: Learn to program proper!

    This codebase is a huge W-T-clusterFuck.

    1.) Violation of separation-of-concerns / single-responsibility-principle. Implementing too many functionality in each method. 2.) Misleading method names: "ReturnEmptyStringIfNullElseValue" does not return the value, it returns the trimmed value. 3.) Violation of Don't-Repeat-Yourself all over the place. Why the animosity against temporary / local variables? And that replace-code is repeated all over again instead of put into a separate method. 4.) What's the point of first parsing as Int and if that fails, parsing as Decimal? Why not parse it as decimal from the beginning? 5.) Other WTfs already pointed out: Calling ToString() on a string, inefficient coding: using Substring instead of an indexer to retrieve a single Char from a String. 6.) What's the idea of accepting input data and convert it into a number even if it is not a number? One might accept the idea that a money input may be in the form "$123.45", but this code will also accept ",7$56$,18.$9". This is worse than PHP!

  • Ben Jammin (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.

    This was my initial assumption on the matter. It has been a while since I've played in 1.1, so I don't remember everything it lacked, but as the guy who wrote the code is supposedly retiring, I don't doubt he had old libraries.

  • Some Jerk (unregistered) in reply to nisl
    nisl:
    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?

    Ummm... where is all this commentary about basic coming from? That was c# code in the story.

    Finally... as to your ignorant comment... well... all I can say is that the coder makes the app, not the language. VB and c# are both converted to clr, and both compiled to run on .NET framework. The result is dictated by the imagination and knowledge of whomever wrote the code... so how that code was expressed carries no relavence whatsoever. My suggestion would be to use whichever language one is comfortable with. I choose c# (when I have a choice) because the syntax is more commonly held across multiple languages, and I have used many. But one who claims that VB or those who use it are in some way intellectually deficient is clearly someone who speaks without knowledge.

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

    Java similar construct:

    String someVal = stringArg == null ? "" : stringArg;

  • tom (unregistered) in reply to blah
    blah:
    The uppercase method names gives a clue as to it being C# and not Java.
    Actually, the first non-blank line suggests it. It says string, not String.
  • n_slash_a (unregistered)

    Apparently -10, 0xA, and 1e1 are all not numbers. One could also make a case about 10.0, but that depends on if your definition of numeric includes floats or just integers.

  • AGray (unregistered)

    I'll take a crack at a Java isNumeric() function:

    public bool isNumeric(string value)
    {
        try
        {
            int ignored = Integer.parseInt(value);
        }
        catch
        {
            return false;
        }
    
        return true;
    }
    

    ...Maybe I'm overthinking this...

  • rawling (unregistered) in reply to AGray

    Throw/catching exceptions in non-exceptional cases: good job.

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

    notNullString = someString ?? string.Empty;

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

    Moot point, the original function checks for "== null". The example I posted would be expanded by the compiler into:

    if (someString == null) notNullString = string.Empty; else notNullString = someString;

  • newbie to site (unregistered) in reply to Loren Pechtel
    Loren Pechtel:
    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.

    Not to beat on a dead horse, but I just love the string.ToString because the 'string' might mysteriously convert itself to some other type. Let's add another one to the library of functions:

    Public Static string GetString(string str) { return str.ToString() }

  • Nagesh (unregistered)

    This ain't being necesary as Java having no null check on parse of Integar from String for performing reason.

    String str = "13";
    int n = -1;
    try {
        n = Integer.parseInt();
    catch (NumberFormatException ex) {}
    catch (NullPointerException ex) {}
    return n >= 0;

    This is meking Nagesh mother cry. [image]

  • Bob (unregistered) in reply to Nagesh
    Nagesh:
    This ain't being necesary as Java having no null check on parse of Integar from String for performing reason.
    String str = "13";
    int n = -1;
    try {
        n = Integer.parseInt();
    catch (NumberFormatException ex) {}
    catch (NullPointerException ex) {}
    return n >= 0;

    This is meking Nagesh mother cry. [image]

    Somebody tell Nagesh to stop showing mother the code !

  • dogmatic (unregistered)

    This reminds me of that George Carlin joke about speeding... "Anybody who knows less about programming than me is an idiot. Anybody who knows more about programming than me is a maniac!"

  • silly (unregistered)

    In the function ReturnDecimalValueOfString(string value) where is OM declared?

    In the function isNumeric(string value) at the very least why use value.Substring(i, 1) as opposed to value(i); why not break out of the loop: for (int i = 0; i < value.Length; i++) { if (!"1234567890".Contains(value.Substring(i, 1))) { isNum = false; //EXIT FOR; //or this //i = value.Length; } }

  • oops (unregistered) in reply to silly
    silly:
    In the function ReturnDecimalValueOfString(string value) where is OM declared?

    That's a Zero, not an O as in Omega. It's a numeric constant, M suffix designates Decimal.

  • now and then (unregistered)

    I have not seen this mentioned yet. In the 'ReturnIntValueOfString' function I would have handled the decimal portion by trimming it as so:

    if(value.IndexOf(".") > -1) {value=value.Substring(0,value.IndexOf("."));}

  • Somebody (unregistered) in reply to Rob
    Rob:
    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!

    There's a (rather large) difference between IIF() and if() in VB.Net (3.5 or 4 ... can't remember) Plus if() can also do the C# ?? operator if using the two argument version.

    if(boolean expression, A, B) if(X,Y) both exists in VB.Net now.

    Always easier to find flaws in other peoples code.

  • PRMan (unregistered) in reply to silly
    silly:
    In the function ReturnDecimalValueOfString(string value) where is OM declared?

    In the function isNumeric(string value) at the very least why use value.Substring(i, 1) as opposed to value(i); why not break out of the loop: for (int i = 0; i < value.Length; i++) { if (!"1234567890".Contains(value.Substring(i, 1))) { isNum = false; //EXIT FOR; //or this //i = value.Length; } }

    Or just "return false;"

  • Jimmy (unregistered) in reply to Severity One
    Severity One:
    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.
    Surely in Java you can say something like String fredBob = ((Jim==NULL)?"":Jim);
  • a;eowri (unregistered) in reply to AGray
    AGray:
    I'll take a crack at a Java isNumeric() function:
    public bool isNumeric(string value)
    {
        try
        {
            int ignored = Integer.parseInt(value);
        }
        catch
        {
            return false;
        }
    
        return true;
    }
    

    ...Maybe I'm overthinking this...

    Would it work for NaN? would it work for null? Staring way too long, and scratching on my skull. A string is not a number, and a number not a string, so functions to convert...who needed such a thing?

  • Yousah (unregistered) in reply to a;eowri
    a;eowri :
    AGray:
    I'll take a crack at a Java isNumeric() function:
    public bool isNumeric(string value)
    {
        try
        {
            int ignored = Integer.parseInt(value);
        }
        catch
        {
            return false;
        }
    
        return true;
    }
    

    ...Maybe I'm overthinking this...

    Would it work for NaN? would it work for null? Staring way too long, and scratching on my skull. A string is not a number, and a number not a string, so functions to convert...who needed such a thing?
    Indeed:

    bool isNumeric(String s)
    {
      return false;
    }
    
  • Some Jerk (unregistered) in reply to a;eowri
    a;eowri :
    AGray:
    I'll take a crack at a Java isNumeric() function:
    public bool isNumeric(string value)
    {
        try
        {
            int ignored = Integer.parseInt(value);
        }
        catch
        {
            return false;
        }
    
        return true;
    }
    

    ...Maybe I'm overthinking this...

    Would it work for NaN? would it work for null? Staring way too long, and scratching on my skull. A string is not a number, and a number not a string, so functions to convert...who needed such a thing?

    This is a joke or are you genuinely curious?

    If you really need it explained, perhaps it would make more sense if I told you that 5 and 53 can be represented by the same value :p.

    Numerically, 53 is a standard integer that can fit in a 1 byte (8 bit) space. If (however) I say ((char)53) then I end up with a '5'.

    As people typically enter numbers in the form of text (and not the way that number looks in memory)... int.Parse( "5" ); would yield the number 5 while (int)"5"[0] would yield 53. If the user enters 5 in a text box, I am grabbing that as a string and would prefer to covert it to the number 5 instead of the number 53... seems a tad more accurate.

  • Veldan (unregistered)

    I had a very similar mess to work with where out coders had decided that all database functions for ALL classes should be kept in the "DatabaseCommon" file and the SQL that those database calls use should be retrieved from "DatabaseCommonSQL" functions...

    Yeah it was fun fixing that :S

    As to the string being null or empty, VB.net covers that nicely:

    Return IIf(String.IsNullOrEmpty(value), "", value)

  • AnonymousCoder (unregistered)

    Ya know, I'm starting to see a pattern here... What I mean is, it looks like these type of "programmers" seem to exhibit the same coding habits. I happen (to have the misfortune !) to work in the company of a couple of them geniuses too, although not as pathetic as the hero of this article.

    Anyway - seems like they all like to abuse string arithmetic! Trim() is their most popular, along with Contains(), Upper(), Split() and last but not least - Substring(). Another "feature" of their code is conversion of basic types to string and back. One of my guys once told me that (quote) "the string is the most user-friendly type in the world"...

  • AnonymousCoder (unregistered)

    I think I'll post some gems on WTF.com too. The author of this article mentioned that the Functions class had "thousands-of-lines", which made me remember the cold reality that I'm in. I've got a class with 10,000 (that's right, TEN THOUSANDS) lines, and growing. Wait till I show you what's in there ! It's a horror story !

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

    Funny, I hardly ever use Python's ternary operator. If something is "something_positive or default" I just use "or", once I've written "foo if this else bar", I find I want to break it out into a proper block anyway.

    Why do you want operator overloading (or did you mean short-circuiting?) in VB? VB has bog-simple semantics by design: it's BASIC for crying out loud.

  • Milde (unregistered) in reply to AnonymousCoder
    AnonymousCoder:
    I think I'll post some gems on WTF.com too. The author of this article mentioned that the Functions class had "thousands-of-lines", which made me remember the cold reality that I'm in. I've got a class with 10,000 (that's right, TEN THOUSANDS) lines, and growing. Wait till I show you what's in there ! It's a horror story !
    I jusr can't wait....and unless you posted it last week, it probably won't happen in my lifetime...
  • not a;eowri (unregistered) in reply to Some Jerk
    Some Jerk:
    a;eowri :
    AGray:
    I'll take a crack at a Java isNumeric() function:
    public bool isNumeric(string value)
    {
        try
        {
            int ignored = Integer.parseInt(value);
        }
        catch
        {
            return false;
        }
    
        return true;
    }
    

    ...Maybe I'm overthinking this...

    Would it work for NaN? would it work for null? Staring way too long, and scratching on my skull. A string is not a number, and a number not a string, so functions to convert...who needed such a thing?

    This is a joke or are you genuinely curious?

    If you really need it explained, perhaps it would make more sense if I told you that 5 and 53 can be represented by the same value :p.

    Numerically, 53 is a standard integer that can fit in a 1 byte (8 bit) space. If (however) I say ((char)53) then I end up with a '5'.

    As people typically enter numbers in the form of text (and not the way that number looks in memory)... int.Parse( "5" ); would yield the number 5 while (int)"5"[0] would yield 53. If the user enters 5 in a text box, I am grabbing that as a string and would prefer to covert it to the number 5 instead of the number 53... seems a tad more accurate.

    Hmmm.....looks genuinely serious to me....

  • Jon Haugsand (unregistered) in reply to no laughing matter
    no laughing matter:
    To all of you defending this code: Learn to program proper!

    This codebase is a huge W-T-clusterFuck.

    1.) Violation of separation-of-concerns / single-responsibility-principle. Implementing too many functionality in each method. 2.) Misleading method names: "ReturnEmptyStringIfNullElseValue" does not return the value, it returns the trimmed value. 3.) Violation of Don't-Repeat-Yourself all over the place. Why the animosity against temporary / local variables? And that replace-code is repeated all over again instead of put into a separate method. 4.) What's the point of first parsing as Int and if that fails, parsing as Decimal? Why not parse it as decimal from the beginning? 5.) Other WTfs already pointed out: Calling ToString() on a string, inefficient coding: using Substring instead of an indexer to retrieve a single Char from a String. 6.) What's the idea of accepting input data and convert it into a number even if it is not a number? One might accept the idea that a money input may be in the form "$123.45", but this code will also accept ",7$56$,18.$9". This is worse than PHP!

    Bad coding, yes, but hardly a WTF.

    /Jon

  • (cs) in reply to no laughing matter
    no laughing matter:
    To all of you defending this code: This codebase is a huge W-T-clusterFuck.

    1.) Violation of separation-of-concerns / single-responsibility-principle. Implementing too many functionality in each method.

    I can't see that here. Each method is doing one job of parsing a string. That the outer class is called "Functions" and not "String conversion functions" or whatever is part of the language WTF of C# (and Java) not allowing free-functions (ideally in extendable namespaces) and forcing you to put everything in a class.
    2.) Misleading method names: "ReturnEmptyStringIfNullElseValue" does not return the value, it returns the trimmed value.
    Slightly misleading yes and verbose but not totally misleading as trimming is part of the logic.
    3.) Violation of Don't-Repeat-Yourself all over the place. Why the animosity against temporary / local variables? And that replace-code is repeated all over again instead of put into a separate method.
    Probably if it should be there at all and if there's a good way to refactor it.
    4.) What's the point of first parsing as Int and if that fails, parsing as Decimal? Why not parse it as decimal from the beginning?
    There can be a point sometimes in doing this, if most of your input is ints and the int parsing is a lot faster then it is an efficiency.
    5.) Other WTfs already pointed out: Calling ToString() on a string, inefficient coding: using Substring instead of an indexer to retrieve a single Char from a String.
    Of course in C++ you get a char from a string with a straight-forward []. C# and Java don't like to see strings as a sequence of chars but what the hell else are they? Of course we know that in UTF-8 not every logical character is a single char but I don't think that's any different in Java and C#.
    6.) What's the idea of accepting input data and convert it into a number even if it is not a number? One might accept the idea that a money input may be in the form "$123.45", but this code will also accept ",7$56$,18.$9". This is worse than PHP!
    Would come under the C++ definition of "undefined behaviour" where the compiler / system is not enforced to have a fixed behaviour when you do an illegal operation. If you input garbage you get "undefined behaviour" here in that it might process it or might not. In reality you won't ever get that input and if you treat it as an UB situation it is not a WTF.
    Learn to program proper!

    I am sure if I had to solve this situation in a language that is not my own I would have avoided some of the WTFs there but my code probably wouldn't be that great.

    The real WTF though is that your comment got featured while none of my comments on the C++ WTF we had a week or two ago got featured, in fact Alex decided to have a day off featuring comments on that WTF. It's a WTF that Alex never featuers any of my comments and I will continue to moan about it on here every day until he does.

  • (cs) in reply to Jimmy
    Jimmy:
    Severity One:
    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.
    Surely in Java you can say something like String fredBob = ((Jim==NULL)?"":Jim);
    Well, yes, obviously, but this becomes tedious if you have to do with for several strings, and if it's not a simple variable but the return value from a method. The C# construct doesn't require the 'Jim' variable/expression twice.
  • Grzes (unregistered) in reply to no laughing matter
    To all of you defending this code: Learn to program proper!

    This codebase is a huge W-T-clusterFuck.

    (...)

    I'm a programmer, not a philosopher, so I won't argue with such grandiloquent phrases as separation-of-concerns and single-responsibility-principle. I believe you are right (for most points), maybe in the Java world there is an emphasis on doing things in accordance to some specific doctrines and if it actually works is a secondary issue.

    However, I don't agree with point 5. I strongly deem that using both words "Java" and "efficiency" in one sentence is a stylistic error, because these words are simply incompatible.

    If you care about efficiency, don't use Java. If you use Java, don't aim for efficiency, because this is something you already lost choosing Java.

  • (cs) in reply to Cbuttius
    Cbuttius:
    I can't see that here. Each method is doing one job of parsing a string.
    Let's check this: * ReturnEmptyStringIfNullElseValue: Convert's nulls into empty string. Trims non-null strings. Two separate functionalities. * ReturnIntValueOfString: Again convert's nulls into empty string and trims non-null strings. Additionally it replaces "$" and "," with "", then tries to parse as Integer, after that tries to parse as Decimal. Converts null and empty string to 0. Six separate functionalities.
    Cbuttius:
    There can be a point sometimes in doing this, if most of your input is ints and the int parsing is a lot faster then it is an efficiency.
    If efficiency was a concern, then this code fails for repeating the same operations over and over again.
    Cbuttius:
    Of course in C++ you get a char from a string with a straight-forward []. C# and Java don't like to see strings as a sequence of chars
    Wrong!

    In Java, String implements the CharSequence interface, so it definitely sees strings as a sequence as chars. It does not provide the []-operator, you have to use the charAt(int) - method.

    C# does provide the []-operator.

    Cbuttius:
    Of course we know that in UTF-8 not every logical character is a single char but I don't think that's any different in Java and C#.
    That's correct, but not relevant for the code in question, as Substring() also operates on sequences of 16Bit-characters, not Unicode codepoints.
    Cbuttius:
    Would come under the C++ definition of "undefined behaviour" where the compiler / system is not enforced to have a fixed behaviour when you do an illegal operation. If you input garbage you get "undefined behaviour" here in that it might process it or might not. In reality you won't ever get that input and if you treat it as an UB situation it is not a WTF.
    If that input data comes from user input there is no guarantee that you won't get that input (as we already know, cats like to sleep on keyboards) and the correct behaviour is to reject such erronous input.
    Cbuttius:
    I am sure if I had to solve this situation in a language that is not my own I would have avoided some of the WTFs there but my code probably wouldn't be that great.
    As others already have suggested: Use the methods / libraries that are part of the platform instead of re-inventing them poorly.
    Cbuttius:
    The real WTF though is that your comment got featured while none of my comments on the C++ WTF we had a week or two ago got featured, in fact Alex decided to have a day off featuring comments on that WTF. It's a WTF that Alex never featuers any of my comments and I will continue to moan about it on here every day until he does.
    I have also noticed that in the last weeks Alex performance in the featuring department was very poor. He seems to be trying to overcompensate for this now, so maybe in a few days he might get a better review on his core field of action from you!

    Just keep on reading yourdailyfeaturedcomment.com.

  • Some Jerk (unregistered) in reply to Grzes
    Grzes:

    If you care about efficiency, don't use Java. If you use Java, don't aim for efficiency, because this is something you already lost choosing Java.

    Point of fact... yes... Java runs like an old hound with only 2 legs and a severe case of IBS on a Windows system... primarily when utilizing the UI components. This problem exists exclusively for Windows however. Running a Java app on Fedora or any Mac/Nix OS will yield much more positive results. Therefore, many people choose to use Java and manage to incorporate efficiency quite well. They are simply writing the code to execute within its' native environment.

  • Yojin (unregistered)

    I've got a variant of ReturnIntValueOfString function in a few of my classes where I needed to do a lot of converting strings (that were often null or blank) into integers...

    Is mine a WTF?

    private static int ToIntOrZero(this string str) { if(string.IsNullOrWhiteSpace(str)) return 0; // quick return.

    int val = 0;
    int.TryParse(str, out val);
    return val;
    

    }

  • Some Jerk (unregistered) in reply to Cbuttius

    [quote user="Cbuttius] The real WTF though is that your comment got featured while none of my comments on the C++ WTF we had a week or two ago got featured, in fact Alex decided to have a day off featuring comments on that WTF. It's a WTF that Alex never featuers any of my comments and I will continue to moan about it on here every day until he does.

    [/quote] That is surprising to read so directly from someone. Do you ever go to your friend's house and complain that he drinks someone else's beer and never your own? This website is a lot of fun, and it is enjoyable to be vocal and all... but bottom line, this is Alex's personal space that we are privileged to share.

    I suspect that the comments that are featured are featured because Alex enjoyed reading them. I seriously doubt the name next to the post is even considered. Therefore... if getting featured means so much to you, then spend more time thinking before you post... and post something that is interesting to read.

  • Some Jerk (unregistered) in reply to Some Jerk

    :( I broke it

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

    This does NOT produce the same results.

    I think you could do it with:

    return (someString ?? string.Empty).Trim();

  • Some Jerk (unregistered) in reply to Loren Pechtel
    Loren Pechtel:
    default_ex:
    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.

    This does NOT produce the same results.

    I think you could do it with:

    return (someString ?? string.Empty).Trim();

    return string.Format("{0}", someString).Trim();

  • AnonymousCoder (unregistered) in reply to Grzes
    I'm a programmer, not a philosopher

    If you are a programmer, you are a philosopher too, even if you don't realize that. Granted, those grandiloquent words sound like mouthful, but so is "deterministic finite state automaton", or "binary space partitioning trees", or even "object-oriented programming", although the latter term may appear cryptic only to outsiders.

    Just by the fact that you are reading this article, and engaging in arguments over coding practices - that in itself is philosophy.

  • Craig (unregistered) in reply to nisl

    Wow, you really are one of those arrogant pricks, aren't you?

    There's nothing wrong with VB.NET. Personally, I prefer C# and that's what I do for my job. But ultimately either language is syntactic sugar over the .NET Framework. As long as you're not writing your VB.NET like it's VB6 then I really don't see a problem with an individual or company settling on it as their language of choice.

  • Some Jerk (unregistered) in reply to Craig
    Craig:
    Wow, you really are one of those arrogant pricks, aren't you?

    There's nothing wrong with VB.NET. Personally, I prefer C# and that's what I do for my job. But ultimately either language is syntactic sugar over the .NET Framework. As long as you're not writing your VB.NET like it's VB6 then I really don't see a problem with an individual or company settling on it as their language of choice.

    Glad I am not the only one who sees it that way. Perhaps next year we will see people suggesting that the real WTF is that the coder was wearing blue when they wrote the code.

    I think arrogant might not be the most precise term however. How does ignorant and E-Biggot work for you?

  • Craig's friend (unregistered) in reply to Craig

    So true... I saw some kids complaining about why no generic and why using arraylist etc without knowing they were looking at .NET 1.0 or 1.1 as they never seen one before.

    These kids tend to create super cool linq code that loops and loops and loops and loops and wondering why their newly reengineered fancy code takes 30 minutes to produce output whilst that old clumpsy code took just few seconds to do the same job..

    TRWTF is really these arrogant kids with shallow knowledge not willing to understand why certain things are done in certin ways. Sure, string to string looks real stupid, but guys, it may be written by someone who is maybe less intelligent than you are.

    Also not only we use to write isnullorempty,but also isnullorwhitespace ourselves with exactly the same name not so long ago. Now some kids will say why you would do this and do that.. They just assume you are stupid before even ask you why.

    I really enjoy reading here and also find it mostly funny but this one just remind me of few kids with full of egos.

  • (cs) in reply to AnonymousCoder
    AnonymousCoder:
    If you are a programmer, you are a philosopher too, even if you don't realize that. Granted, those grandiloquent words sound like mouthful, but so is "deterministic finite state automaton", or "binary space partitioning trees", or even "object-oriented programming", although the latter term may appear cryptic only to outsiders.
    I am wondering why your list does not include the grandiloquent Monad from functional programming.
  • (cs) in reply to Craig's friend
    Craig's friend:
    So true... I saw some kids complaining about why no generic and why using arraylist etc without knowing they were looking at .NET 1.0 or 1.1 as they never seen one before.
    So false! As already explained by nisl, he was using TryParse, so he was using at least .NET 2.0.

    In other words: The post you are referring to is not "So true", it is only proof of even more ignorance!

    Craig's friend:
    TRWTF is really these arrogant kids with shallow knowledge not willing to understand why certain things are done in certin ways. Sure, string to string looks real stupid, but guys, it may be written by someone who is maybe less intelligent than you are.
    String to string is just a sure sign that the programmer was just to dumb to program at all.
  • (cs) in reply to no laughing matter
    no laughing matter:
    To all of you defending this code: Learn to program proper!

    This codebase is a huge W-T-clusterFuck.

    1.) Violation of separation-of-concerns / single-responsibility-principle. Implementing too many functionality in each method. 2.) Misleading method names: "ReturnEmptyStringIfNullElseValue" does not return the value, it returns the trimmed value. 3.) Violation of Don't-Repeat-Yourself all over the place. Why the animosity against temporary / local variables? And that replace-code is repeated all ovparsinger again instead of put into a separate method. 4.) What's the point of first as Int and if that fails, parsing as Decimal? Why not parse it as decimal from the beginning? 5.) Other WTfs already pointed out: Calling ToString() on a string, inefficient coding: using Substring instead of an indexer to retrieve a single Char from a String. 6.) What's the idea of accepting input data and convert it into a number even if it is not a number? One might accept the idea that a money input may be in the form "$123.45", but this code will also accept ",7$56$,18.$9". This is worse than PHP!

    Thank you, yes. It's not so much that the functions exist, it's that they're full of bugs!

    While we're at it, isNumeric fails on floating point strings, etc.

  • Stefan (unregistered)

    I would not call the isNumeric code "one of the more... clever approaches". In Perl, my regular check that a string is a positive integer is

    if ($value =~ /^\d+$/) { ...

    The only other alternative is to load the

    Scalar::Util::looks_like_number
    function. Or you just convert to integer and live with the warning on standard error. Meh.

  • Paul Neumann (unregistered)

    I like to include a .ToString() on a string reference at times, like when I'm writing a jump tree where every other branch has .ToString(), or when punching a bunch of other typed objects into a string collection. It generally makes the code quicker for the reader to digest.

    Also, in .NET, the compiler will see the implementation of String.ToString(), specifically "return this;" being the only statement in the body. It will be then inlined and in the next processing step, removed as redundant. There really is no efficiency concern. Even if there were, if you're concerned about a single jump, then NO vm based language is for you. Not Java, any .NET variant, Python, Perl, or PHP. From the looks, we only have one person here capable of C/C++ regurgitation. And a TRUE efficiency die hard would complain of the inefficiencies that C adds to the code. ASM or NOTHING!

    The real WTF here is that all of you "experienced" programmers here apparently cannot tell the difference between Java and C#. Even more disturbing is the number of contributers which do not realize this is not actually VB.NET

  • AnonymousCoder (unregistered) in reply to no laughing matter
    I am wondering why your list does not include the grandiloquent Monad from functional programming.

    Because otherwise I'll end up sounding like the Architect I've no idea what the hell I'm saying... (watch at 56s)

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

Log In or post as a guest

Replying to comment #:

« Return to Article