• Anon (unregistered)

    The goggles...they do nothing!

  • Chishm (unregistered)

    The for-case paradigm has re-appeared, worse than ever

  • captain obvious (unregistered)

    How does it get through to someone's mind that this is okay? This is wrong on so many levels, for example:

    deduction_breakfast / deduktion_lunch / deduktion_dinner Note that only once is "deduction" spelt correctly... how the f?

  • Rob (unregistered)

    I like the absence of any checks against null - not only the elements, but the array itself as well. Just one occurrance and the entire constructor fails.

  • NaN (cs)

    I'm guessing the class has a list of all the instances (lineItems) but this list is cleared each time a new LineItem is instantiation, so it contains a list of only the last lineItem:

    In the constructor: lineItems = new List(0);

  • McWyrm (unregistered) in reply to Chishm
    Chishm:
    The for-case paradigm has re-appeared, worse than ever

    This strikes me as a particularly elegant implementation of the paradigm, though. Almost as if the programmer's technique has been polished over the course of a lengthy practice.

    wtf?!

  • TGV (cs)

    Why do I get the feeling that the person who wrote this has not idea what a database is? Or what you can do with SQL? Let me guess: all (s)he knows is "SELECT * FROM %s" and that is read into this horrible data structure...

  • Marcel Veldhuizen (unregistered)

    Apart from the use of strings and the foreach/switch instead of a normal for-loop, I don't find this code all that strange. Sure, there are other ways to do this, but I don't consider a strongly typed dataset a viable alternative for value objects.

    I wonder how the field data ends up in the object array initially though, that's something to be avoided. Straight from DataReader or DataRow to value object would make more sense.

  • NaN (cs) in reply to NaN

    As for what and why - I'm guessing these are the expected results from the test, and they compare the objects toString method with these strings, rather than a full object.

  • Codepope (unregistered)

    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

  • NaN (cs) in reply to NaN

    For-case VS Unrolled loop VS Normal Loop:

    An Unrolled loop would use a few lines less code.

    The For-Case only loops while there are objects, so as long as no one added a null object, it would be fine. Also, if there are only 10 objects, it would stop at 10 (well, 9) whereas an unrolled loop would need checking.

    A normal loop would be able to loop through everything AND stop at the last one should that happen early.

    Normal loop:

    String array of all the variables. Loop, use indexes to assign to array of all variables.

    Is it strange I don't think this isn't too bad?

  • Frodo (unregistered) in reply to captain obvious
    captain obvious:
    How does it get through to someone's mind that this is okay? This is wrong on so many levels, for example:

    deduction_breakfast / deduktion_lunch / deduktion_dinner Note that only once is "deduction" spelt correctly... how the f?

    Not only that - if the company hires some Hobbits and has to add 'deduction_second_breakfast' to the line item, it will completely break the code.

  • Someone You Know (cs) in reply to Codepope
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    For those of us who don't know C#: what is the difference?

  • benryves (unregistered) in reply to Codepope
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    This is C#, hence Object.ToString() rather than object.toString().

  • NaN (cs) in reply to Someone You Know
    Someone You Know:
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    For those of us who don't know C#: what is the difference?

    I think one works and one doesn't. (Guessing)

  • Patryk Zawadzki (cs)

    It's simple guys, he must have deduked it was a good idea.

    BTW, Deduktion == you are no longer a duke, right?

  • justAnotherCoder (unregistered) in reply to Someone You Know
    Someone You Know:
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    For those of us who don't know C#: what is the difference?

    Methods begin with upper case in C#'s naming convention. So ToString() is the correct one, defined in Object.

  • ath (unregistered)

    It's not that WTF:y. I can't really think of any easier way of implementing the same functionality. Sure, implementing similar more logical functionality yes, but the same?

    Notice how: o.LineItem({"Rent", "Cash"}); will only set the parameters category, and payment method which is perfect for the lazy programmer who doesnt like to create new objects.

    So: o.LineItem({"Rent", "Cash", "Today", "Two millions"}); o.LineItem({"Prince of Nigeria help", "Credit Card"}); Will send two millions today to both my landlord and the prince of nigeria, using different payment methods. Excellent!

  • Dave (unregistered) in reply to Anon
    Anon:
    The goggles...they do nothing!

    Why do people consistently misquote that line?

  • Ben (unregistered) in reply to Codepope

    That's not a code-smell. It's just C# where the convention is MethodsLikeThis() (as in Pascal) and not methodsLikeThis() (as in Java).

  • Who Cares (unregistered)

    How about using a default case with ToString and only cases IF there is something else? In that case you could strip the switch altogether until somebody really adds something else than a string there.

    After all... duplicate code smells

  • Leo Davidson (unregistered)

    Looks like a Perl programmer tried to write C#. Yuck.

  • ChipK (unregistered)

    Wow, cool, I am going to cut-n-paste this code into the app I am maintaining... it will blend right in!

  • M L (unregistered) in reply to Codepope
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    That's just the subtle smell of C# and not the Java you thought you were smelling. It is normal C# code style to have capitalized method names. (Also note the foreach loop is not Java's either.)

  • John the incredible (unregistered)

    Seems ungraceful. They should have just used nothing but objects for storage and then cast them to strings for output...

  • bbqfrito (unregistered) in reply to ChipK
    ChipK:
    Wow, cool, I am going to cut-n-paste this code into the app I am maintaining... it will blend right in!

    Sorry.

  • Codepope (unregistered) in reply to benryves

    Ah. The just being not Java thing....

    Actually, wouldn't it be a good idea for Daily WTF to actually label code segments with what language they are meant to be rather than making the reader infer it from the text.

  • Codepope (unregistered) in reply to M L
    M L:
    (Also note the foreach loop is not Java's either.)

    Oh yes; slaps forehead, leaves mark, goes ouch.

  • Pauldy (unregistered)

    Not realy much of a WTF esp if this data access layer is meant specifically for display on some type of form only. Of course you would have to know the database layout etc... because if nulls are allowed then I could see this being a wtf.

  • SomeCoder (unregistered) in reply to Dave
    Dave:
    Anon:
    The goggles...they do nothing!

    Why do people consistently misquote that line?

    "My eyes... the goggles do nothing!"

    Rainier Wolfcastle (The Simpsons)

    :)

  • Outlaw Programmer (cs) in reply to Pauldy

    What's the point of using the whole loop-and-switch construct, anyway? All other WTFs aside, couldn't he have done:

    category = field[0].ToString(); paymentMethod = field[1].ToString(); ...

    ? (insert check for null if necessary)

  • KenW (cs) in reply to Dave
    Dave:
    Why do people consistently misquote that line?

    Why do pedants who care about stuff like this exist?

    Seriously, dude... Get a life! If slight misquoting gets your shorts in a bunch, you need to get laid or something.

  • j0k3r (cs) in reply to ath
    ath:
    It's not that WTF:y. I can't really think of any easier way of implementing the same functionality. Sure, implementing similar more logical functionality yes, but the same?

    Notice how: o.LineItem({"Rent", "Cash"}); will only set the parameters category, and payment method which is perfect for the lazy programmer who doesnt like to create new objects.

    So: o.LineItem({"Rent", "Cash", "Today", "Two millions"}); o.LineItem({"Prince of Nigeria help", "Credit Card"}); Will send two millions today to both my landlord and the prince of nigeria, using different payment methods. Excellent!

    Oh but it is. If you really want all strings, for whatever reason that may be, you should override your correctly formed dataset.
  • Some Java Guy (unregistered)

    So the real WTF is C#.

    Is that even a real programming language?

  • NaN (cs) in reply to Some Java Guy
    Some Java Guy:
    So the real WTF is C#.

    Is that even a real programming language?

    It's A programming language. The REAL WTF is that it's possible you didn't anticipate the small war your going to cause...

  • dkf (unregistered) in reply to Outlaw Programmer
    Outlaw Programmer:
    What's the point of using the whole loop-and-switch construct, anyway? All other WTFs aside, couldn't he have done:

    category = field[0].ToString(); paymentMethod = field[1].ToString();

    It's there to stop the code from charging off the end of the array. Mind you, it's possibly better to do what you're suggesting and wrap it with code to trap a read off the end of the array. Like that it will be much more efficient due to avoiding a counter variable...

  • notJoeKing (unregistered) in reply to Some Java Guy
    Some Java Guy:
    So the real WTF is C#.

    Is that even a real programming language?

    Nope, it's just the bastard child of Java and C++... they made it for all the C++ programmers who needed an easier and faster environment to develop in. C# was only created because C++ developers were too Prima Donna to switch to VB.Net... Or maybe they just couldn't learn the syntax ;)

    {Putting on flame suit for the prissy C++/C# diciples...)

    LOL

  • hikari (cs) in reply to NaN
    NaN:
    It's A programming language. The REAL WTF is that it's possible you didn't anticipate the small war your going to cause...

    Oh I think they knew exactly what they were doing.

  • Al (unregistered) in reply to notJoeKing
    notJoeKing:
    C# was only created because C++ developers were too Prima Donna to switch to VB.Net...

    VB.Net is the real WTF.

  • Chris M. (unregistered) in reply to notJoeKing
    notJoeKing:
    Some Java Guy:
    So the real WTF is C#.

    Is that even a real programming language?

    Nope, it's just the bastard child of Java and C++... they made it for all the C++ programmers who needed an easier and faster environment to develop in. C# was only created because C++ developers were too Prima Donna to switch to VB.Net... Or maybe they just couldn't learn the syntax ;)

    {Putting on flame suit for the prissy C++/C# diciples...)

    LOL

    Well, no. It was actually made for Microsoft managers, who get hives when large numbers of developers or users start using things they can't hold absolute control over, like Java.

  • Roots (unregistered) in reply to NaN

    It's probably an internal list of child lineItems. Nested line items seems plausible I suppose.

  • Chris M. (unregistered) in reply to captain obvious
    captain obvious:
    How does it get through to someone's mind that this is okay? This is wrong on so many levels, for example:

    deduction_breakfast / deduktion_lunch / deduktion_dinner Note that only once is "deduction" spelt correctly... how the f?

    Five will get you ten the native language of the original programmer was German.

  • Dan (unregistered) in reply to ath
    ath:
    It's not that WTF:y. I can't really think of any easier way of implementing the same functionality. Sure, implementing similar more logical functionality yes, but the same?

    I don't know a lick of C#, but I can't imagine any modern programming language in which the use of magic numbers in a switch-type statement is considered best practices.

    Dan.

  • fuzzylollipop (unregistered)

    the real WTF is the List(0), which creates the worst case degenerate list behavior possible. It will do memory allocation on almost every add!

  • An apprentice (unregistered)

    But it's so intuitive. For example you can write:

    deduction_breakfast + deduktion_lunch + deduktion_dinner
    and it will compile successfully.

  • Someone You Know (cs) in reply to justAnotherCoder
    justAnotherCoder:
    Someone You Know:
    Codepope:
    I like the use of .ToString() rather than .toString()...

    It's subtle but full aroma code smell... :)

    For those of us who don't know C#: what is the difference?

    Methods begin with upper case in C#'s naming convention. So ToString() is the correct one, defined in Object.

    Oh, I see. Codepope made it sound like they both existed, but one of them was a good thing to do and the other not. That would certainly qualify as a WTF to me...

  • nerfer (unregistered) in reply to Codepope
    Codepope:
    Ah. The just being not Java thing....

    Actually, wouldn't it be a good idea for Daily WTF to actually label code segments with what language they are meant to be rather than making the reader infer it from the text.

    It's a good litmus test, separating the people who actually know what they're talking about from the others. I use C/C++, not C# or Java, but there's a couple WTFs that carry over (incremented switch inside a loop being the most obvious one), and the others I would let more knowledgeable people comment on.

    But lack of knowledge doesn't stop everybody here from commenting on things, sometimes the best WTFs are in the comments.

  • AT (unregistered) in reply to Chris M.
    Chris M.:
    notJoeKing:
    Some Java Guy:
    So the real WTF is C#.

    Is that even a real programming language?

    Nope, it's just the bastard child of Java and C++... they made it for all the C++ programmers who needed an easier and faster environment to develop in. C# was only created because C++ developers were too Prima Donna to switch to VB.Net... Or maybe they just couldn't learn the syntax ;)

    {Putting on flame suit for the prissy C++/C# diciples...)

    LOL

    Well, no. It was actually made for Microsoft managers, who get hives when large numbers of developers or users start using things they can't hold absolute control over, like Java.

    Well, no. It was actually made to provide a from-scratch, managed-code environment well-suited to Windows development. MS tried integrating Java with Windows and Sun sued to stop them. You may believe MS did this to protect its OS monopoly, but regardless of that the J/Direct technology created by Sun was much nicer to work with on Windows than JNI.

  • VGR (cs) in reply to Codepope

    There is a code smell here, but it's not related to the language used. It's the smell of premature optimization. This is clearly superior because the caller might not want to specify all the fields! I'm sure the array is even ordered by importance/dependency.

  • smxlong (cs)

    Ok, it's a little hokey, but I don't see what the problem is. If a new field is added, this code requires the addition of only a single line of code -- a new case. Each of you, ask yourselves, under your solution (whatever that might be), how many lines would YOU need to add a field? I'm not saying it can't be done some other way, but I really am not seeing a WTF here.

Leave a comment on “Type Safety Considered Harmful”

Log In or post as a guest

Replying to comment #:

« Return to Article