- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The goggles...they do nothing!
Admin
The for-case paradigm has re-appeared, worse than ever
Admin
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?
Admin
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.
Admin
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);
Admin
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?!
Admin
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...
Admin
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.
Admin
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.
Admin
I like the use of .ToString() rather than .toString()...
It's subtle but full aroma code smell... :)
Admin
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?
Admin
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.
Admin
For those of us who don't know C#: what is the difference?
Admin
Admin
I think one works and one doesn't. (Guessing)
Admin
It's simple guys, he must have deduked it was a good idea.
BTW, Deduktion == you are no longer a duke, right?
Admin
Methods begin with upper case in C#'s naming convention. So ToString() is the correct one, defined in Object.
Admin
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!
Admin
Why do people consistently misquote that line?
Admin
That's not a code-smell. It's just C# where the convention is MethodsLikeThis() (as in Pascal) and not methodsLikeThis() (as in Java).
Admin
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
Admin
Looks like a Perl programmer tried to write C#. Yuck.
Admin
Wow, cool, I am going to cut-n-paste this code into the app I am maintaining... it will blend right in!
Admin
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.)
Admin
Seems ungraceful. They should have just used nothing but objects for storage and then cast them to strings for output...
Admin
Sorry.
Admin
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.
Admin
Oh yes; slaps forehead, leaves mark, goes ouch.
Admin
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.
Admin
"My eyes... the goggles do nothing!"
Rainier Wolfcastle (The Simpsons)
:)
Admin
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)
Admin
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.
Admin
Admin
So the real WTF is C#.
Is that even a real programming language?
Admin
It's A programming language. The REAL WTF is that it's possible you didn't anticipate the small war your going to cause...
Admin
Admin
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
Admin
Oh I think they knew exactly what they were doing.
Admin
VB.Net is the real WTF.
Admin
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.
Admin
It's probably an internal list of child lineItems. Nested line items seems plausible I suppose.
Admin
Five will get you ten the native language of the original programmer was German.
Admin
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.
Admin
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!
Admin
But it's so intuitive. For example you can write:
and it will compile successfully.Admin
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...
Admin
But lack of knowledge doesn't stop everybody here from commenting on things, sometimes the best WTFs are in the comments.
Admin
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.
Admin
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.
Admin
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.