|
|
|
| Non-WTF Job: Software Developer at Rustici Software (Franklin, Tennessee) |
| « Prev | Page 1 | Page 2 | Next » |
|
The goggles...they do nothing!
|
|
The for-case paradigm has re-appeared, worse than ever
|
Re: Type Safety Considered Harmful
2008-03-19 08:10
•
by
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? |
|
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.
|
|
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); |
Re: Type Safety Considered Harmful
2008-03-19 08:45
•
by
McWyrm
(unregistered)
|
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?! |
|
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...
|
Re: Type Safety Considered Harmful
2008-03-19 08:48
•
by
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. |
|
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.
|
|
I like the use of .ToString() rather than .toString()...
It's subtle but full aroma code smell... :) |
|
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? |
Re: Type Safety Considered Harmful
2008-03-19 08:58
•
by
Frodo
(unregistered)
|
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. |
Re: Type Safety Considered Harmful
2008-03-19 08:59
•
by
Someone You Know
|
For those of us who don't know C#: what is the difference? |
Re: Type Safety Considered Harmful
2008-03-19 09:00
•
by
benryves
(unregistered)
|
This is C#, hence Object.ToString() rather than object.toString(). |
I think one works and one doesn't. (Guessing) |
|
It's simple guys, he must have deduked it was a good idea.
BTW, Deduktion == you are no longer a duke, right? |
Re: Type Safety Considered Harmful
2008-03-19 09:02
•
by
justAnotherCoder
(unregistered)
|
Methods begin with upper case in C#'s naming convention. So ToString() is the correct one, defined in Object. |
|
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! |
Re: Type Safety Considered Harmful
2008-03-19 09:18
•
by
Dave
(unregistered)
|
Why do people consistently misquote that line? |
Re: Type Safety Considered Harmful
2008-03-19 09:20
•
by
Ben
(unregistered)
|
|
That's not a code-smell. It's just C# where the convention is MethodsLikeThis() (as in Pascal) and not methodsLikeThis() (as in Java).
|
Re: Type Safety Considered Harmful
2008-03-19 09:20
•
by
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 |
Re: Type Safety Considered Harmful
2008-03-19 09:25
•
by
Leo Davidson
(unregistered)
|
|
Looks like a Perl programmer tried to write C#. Yuck.
|
|
Wow, cool, I am going to cut-n-paste this code into the app I am maintaining... it will blend right in!
|
Re: Type Safety Considered Harmful
2008-03-19 09:49
•
by
M L
(unregistered)
|
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.) |
Re: Type Safety Considered Harmful
2008-03-19 09:59
•
by
John the incredible
(unregistered)
|
|
Seems ungraceful. They should have just used nothing but objects for storage and then cast them to strings for output...
|
Re: Type Safety Considered Harmful
2008-03-19 10:01
•
by
bbqfrito
(unregistered)
|
Sorry. |
Re: Type Safety Considered Harmful
2008-03-19 10:12
•
by
Codepope
(unregistered)
|
|
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. |
Re: Type Safety Considered Harmful
2008-03-19 10:16
•
by
Codepope
(unregistered)
|
Oh yes; slaps forehead, leaves mark, goes ouch. |
|
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.
|
Re: Type Safety Considered Harmful
2008-03-19 11:03
•
by
SomeCoder
(unregistered)
|
"My eyes... the goggles do nothing!" Rainier Wolfcastle (The Simpsons) :) |
Re: Type Safety Considered Harmful
2008-03-19 11:07
•
by
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(); ... ? (insert check for null if necessary) |
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. |
Re: Type Safety Considered Harmful
2008-03-19 11:44
•
by
j0k3r
|
Oh but it is. If you really want all strings, for whatever reason that may be, you should override your correctly formed dataset. |
Re: Type Safety Considered Harmful
2008-03-19 11:58
•
by
Some Java Guy
(unregistered)
|
|
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... |
Re: Type Safety Considered Harmful
2008-03-19 12:12
•
by
dkf
(unregistered)
|
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... |
Re: Type Safety Considered Harmful
2008-03-19 12:39
•
by
notJoeKing
(unregistered)
|
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 |
Re: Type Safety Considered Harmful
2008-03-19 12:55
•
by
hikari
|
Oh I think they knew exactly what they were doing. |
Re: Type Safety Considered Harmful
2008-03-19 12:59
•
by
Al
(unregistered)
|
VB.Net is the real WTF. |
Re: Type Safety Considered Harmful
2008-03-19 13:40
•
by
Chris M.
(unregistered)
|
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. |
Re: Type Safety Considered Harmful
2008-03-19 13:41
•
by
Roots
(unregistered)
|
|
It's probably an internal list of child lineItems. Nested line items seems plausible I suppose.
|
Re: Type Safety Considered Harmful
2008-03-19 13:41
•
by
Chris M.
(unregistered)
|
Five will get you ten the native language of the original programmer was German. |
Re: Type Safety Considered Harmful
2008-03-19 14:12
•
by
Dan
(unregistered)
|
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. |
Re: Type Safety Considered Harmful
2008-03-19 14:26
•
by
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!
|
Re: Type Safety Considered Harmful
2008-03-19 14:31
•
by
An apprentice
(unregistered)
|
|
But it's so intuitive. For example you can write:
deduction_breakfast + deduktion_lunch + deduktion_dinnerand it will compile successfully. |
Re: Type Safety Considered Harmful
2008-03-19 14:31
•
by
Someone You Know
|
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... |
Re: Type Safety Considered Harmful
2008-03-19 14:33
•
by
nerfer
(unregistered)
|
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. |
Re: Type Safety Considered Harmful
2008-03-19 15:02
•
by
AT
(unregistered)
|
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. |
|
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.
|
|
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.
|
| « Prev | Page 1 | Page 2 | Next » |