- 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
This looks like a Java tutorial.
if (name == "Mickey Mouse") // Legal, but ALMOST SURELY WRONG
http://www.leepoint.net/notes-java/data/expressions/22compareobjects.html
Admin
Improvements may or may not have been made, but that was never the point.
Admin
Finally found the WTF in the first one - it's that java's calendar functions were used instead of joda time.
Admin
The last one always returns false, the one before that nearly always ;)
Admin
That would be the first example, which clearly is Java. We're discussing the second one, which is C#. The clues are using Object.Equals (with uppercase E), meaning it's not Java, and "public static" (instead of "public: static"), meaning it's not C++.
Admin
As others have said, most of these are ok. However, if you're coding in Java, you owe it to yourself to use libraries like Apache Commons Lang which has useful classes like ObjectUtils that handle a lot of the nasty null checking for you.
Admin
bogger baby, i am rollin with lafter all over at your pathetic attempt to seek my attention...
i said before, i hold nothing against trolls, but for sake of everyone on internet, be interesting. Sorry bogger you're number two boring dude!
Admin
Which is a good example of what is wrong with Java. You should not have to automatically have to use a third party library to make a language sane. Which is also a great reason why ECMAscript should be burned to the ground.
Admin
Apache commons? Seriously?
Man, I really want to type something about how absolutely bad those libraries are, but I've been trolled a lot lately. Best be wary here.
Admin
I've written functions like this. In ADO.NET for example, values can be almost any primitive type, and any value can be DBNull (throwing exceptions on comparison). And .equals() between different numeric types (like double vs int) always returns false without checking equality.
Admin
Admin
Admin
Anyone who needs a library to code in ECMAScript needs not to apply to ECMAScript, it's not 2001, and it's not a bad language. ECMA5 brings a lot of sugar to the table to make it a much cleaner language, and as long as you don't try to push a "Class" model onto it, you'll be golden.
Admin
Admin
Admin
Admin
It's actually not a bad idea to do away with NULLs, it removes a lot of worries when programming. Try writing some code in a language that doesn't have NULLs before dismissing the idea (Haskell for example).
Admin
x = Fribbleclass<Doodah,BofBof>::zog( p );
Answer: Could be any of a number of things, and looking at the definition of template<class T, class U> class Fribbleclass will not tell you.
Admin
They should name the function "datesAreEqual", not "dateAreEqual" because the plural form of "date" is "dates".
Admin
Why? Did USA win?
Admin
Admin
Admin
If you can avoid the Apache commons library by instead requiring a later version of Java, do that. You'll have less trouble and more hair.
Admin
The biggest WTF IMO is one of the most common WTFs I see. Anyone that writes code in the form
doesn't understand what a boolean is.Admin
It isn't that they had an epsilon, it's that they used floating-point for money. That's just wrong, wrong, wrong.
Admin
Captha: jumentum - like momentum but younger
Admin
Admin
The problem with NULLs isn't having some "I don't know what this is" type marker, after all, enumerated types work just fine, so there's no reason you can't have a single-value type called null. It's that people can't leave it alone at that. So they come up with idiotic stuff like three-valued logic and try to shoehorn it into relational algebra that is implicitly based on two-valued logic. A table is a set of rows that correspond to logical propositions. If a row is in the table, the database asserts that the corresponding proposition is true, and if it's not, the corresponding proposition is false. So if the corresponding proposition is null, should the row be in the table or not?
And then you have Java, where every "type", if such a term can be used for classes of mutable objects, includes the null type. So every parameter of every function is possibly going to get this null whether it's legal or not. Which is not quite as dumb as C, where the null value for a pointer is... a perfectly valid pointer that just happens to be considered an error condition by the operating system. Complete insanity.
And most people just take this for granted because they've never used a good type system. It's shameful, truly shameful.
Admin
Admin
First time in my entire life, I had more than 6 big beers at one single sitting.
Admin
Don't worry Nagesh, you're in good company here... I'm sure at least half the people on this forum are drunk right now.
Or is that just me?
Admin
Just you, bud. Most of us wait till evening and/or when they've quit work for the day.
Admin
Ahh, good to know I have someone to drive me home from work today... Thanks!
Admin
We need a statistical notation to check if y is within 5 units of x 19 times out of 20. Maybe something like this:
x ~= y
Admin
Meh, Haskell is interesting but not a major mind frell, but if you are a programmer used to the c style syntax/semantics (most common languages) and you REALLY want to fry your brain, try Prolog -- a declarative general purpose logic programming language used in AI applications.
Admin
Admin
No worries but if you puke up on the seat covers you're a dead man.
Admin
Util classes with lots of static methods are really not a good idea in most cases, either it was already done and its just inventing the wheel, or a more object oriented aproach will yeld more readable code without more work.
If you really need to you are better off creating your own classes that wrap the type and add there behaviour you want in methods such has equals(), overlaps(): behaviour such as null checking, prevent exceptions being thrown etc.
In fact if you need such classes for Dates you are better off using the Joda library, with types DateTime (represents a Date plus the time, like Java Date but more user friendly) and DateMidnight (represents a date without the time part).
For user friendly functions to handle Strings with null checks etc like isBlank (check if spaces or null or blank char in general), use Apache commons.
So for me thats the WTF, first its procedural programming and second was already written a million times :-)
Admin
<span style="color:"white";">Great comment!
Admin
But "number one" is frits!
Admin
Anyone who thinks that 'double' thingie is bad just because they store money in it should have a look here:
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
Comparing doubles for equality with fixed epsilon is almost always bad. If its in library then its very bad. It may be good enough occasionally, but its still bad nonetheless.
Admin
In all my years of coding, the terribleness here is unequalled.
Admin
Admin
for those complaining about float for monetary values, how would you suggest storing $0.018372 ?
Not all applications are built for airline tickets and groceries you know...
Admin
For that matter, TRWTF is any language that requires you to explicitly write "!= NULL". It should be enough to do: if(obj1 && obj2 && Math.abs(obj2 - obj1) < EPSILON) doStuff();
Admin
Admin
Again, what is matter with yuo people? I have fixed URL.
Admin
Back when that was legal, it caused a huge amount of problems. What if obj1 is zero? That is/was false in some C implementations, even though it's not null. I'm on board with the requirement that whatever goes in the IF condition should be a boolean expression. There should be no confusion about whether the programmer meant non-zero, non-null, or whatever they meant to say.
Admin
This has Nagesh written all over it.
Admin
This has Nagesh written all over it.