• (cs)

    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

  • TK (unregistered) in reply to Magnus
    Magnus:
    SCSimmons:
    (Or is this where I say "TRWTF is Java"?)
    TRWTH is that both the Java and the C# snippet look exactly the same. I mean, wasn't C# meant to improve on Java?
    No, C# was just plan B when the usual "embrace-and-extend" strategy was thwarted by lawsuits.

    Improvements may or may not have been made, but that was never the point.

  • (cs)

    Finally found the WTF in the first one - it's that java's calendar functions were used instead of joda time.

  • SG_01 (unregistered) in reply to Eisentein
    Eisentein:
    kadal:
    Some equality are more equal than others

    x = y // "y" is assigned to "x" x == y // "y" is logically equivalent to "x", can convert types if required x === y // "y" is identical to "x", no conversion of types allowed x ==== y // "y" is composed of the same electrons as "x" x ===== y // "y" ==== "x" and across all space/time continua

    The last one always returns false, the one before that nearly always ;)

  • Magnus (unregistered) in reply to Vacaloca
    Vacaloca:
    SCSimmons:
    Magnus:
    SCSimmons:
    (Or is this where I say "TRWTF is Java"?)
    TRWTH is that both the Java and the C# snippet look exactly the same. I mean, wasn't C# meant to improve on Java?
    Well, both Java and C# get their basic syntax from C/C++. A lot of code is interchangeable--in fact, I'm not positive glancing over it that the last snippet is C#. (It's not Java, but it could be C++, couldn't it? Or maybe not--I've been using VB.NET too long, so I've lost a lot of brain cells.)

    Sounds like you should go back to VB6 is this wasn't a dead giveaway..

    import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar;

    import org.apache.log4j.Logger;

    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++.

  • Jeff Olson (unregistered)

    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.

  • (cs) in reply to boog
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

  • Gates, Bill (unregistered) in reply to Jeff Olson
    Jeff Olson:
    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.

    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.

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

    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.

  • (cs)

    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.

  • (cs) in reply to boog
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    Oh gawd... he claimed to know C++... holy shit....

  • Anonymous (unregistered) in reply to Nagesh
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Oh God, not another NULL denier... oh, hang on, it's just Nagesh. Troll on you crazy diamond.
  • Anonymoose (unregistered) in reply to Gates, Bill
    Gates:
    Jeff Olson:
    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.

    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.

    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.

  • (cs) in reply to dtfinch
    dtfinch:
    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.
    Which is why, personally, I always cast before I compare.
  • (cs) in reply to oh
    oh:
    most of these are ok. Whoever submitted these just doesn't understand that sometimes you _want_ to say that two things are equal even when they aren't exactly the same.
    I have, on occasion, overloaded == to mean "similar enough", when I needed to prevent new objects that are too similar to existing objects from being persisted into the database.
  • (cs) in reply to Nagesh
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

  • Kalle (unregistered) in reply to Anonymous
    Anonymous:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Oh God, not another NULL denier... oh, hang on, it's just Nagesh. Troll on you crazy diamond.

    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).

  • (cs) in reply to Gates, Bill
    Gates:
    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.
    ECMAScript itself is the best reason why ECMAScript should be burned to the ground. The only reason it doesn't have the flakiest semantics of any programming language on the planet is PHP. Well, OK, PHP and C++ when used by template fanatics. Quick: what does this code do (found in a non-static member function):

    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.

  • Resident Mockery (unregistered)

    They should name the function "datesAreEqual", not "dateAreEqual" because the plural form of "date" is "dates".

  • Naresh Kookaburra (unregistered) in reply to hoodaticus
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    Why? Did USA win?

  • (cs) in reply to Naresh Kookaburra
    Naresh Kookaburra:
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    Why? Did USA win?

    Nah, India wins it every 28 years, so they have to do 28 years worth of drinking in about a week.
  • (cs) in reply to Nagesh
    Nagesh:
    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!
    At least you can sleep easy knowing bogger will never even come close to stealing your "Number One" title.
  • (cs) in reply to Power Troll
    Power Troll:
    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.

    I'd go further than that. There are crippling bugs in at least some of the commons libraries. We found one the other week with the command-line processing library, where it was doing something very odd with processing quotes in arguments. Now, it seems that this had been discovered before, and everyone agreed that it was a bug based on code that really should never have been committed, but there's still no chance of getting a fixed version because there's no chance of getting another release of the library in question (even just a bugfix release). Ick!

    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.

  • O'Malley (unregistered)

    The biggest WTF IMO is one of the most common WTFs I see. Anyone that writes code in the form

    if (...) return true; else return false;
    doesn't understand what a boolean is.

  • Meep (unregistered) in reply to Larrik Jaerico
    Larrik Jaerico:
    The parts with the doubles (ie. abs(double1-double2) < TOLERANCE_CONSTANT) is not really a WTF. Sometimes you certainly can wind up with two values that are only 0.0000001 off or so, which are clearly equal for our purposes, but different to the computer. Either you can round first, or do it this way.

    It isn't that they had an epsilon, it's that they used floating-point for money. That's just wrong, wrong, wrong.

  • Raniz (unregistered) in reply to Kalle
    Kalle:
    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).
    Not trying to start a functional-programming-vs-everything-else flame war here, but coming from an imperative/OO language and trying to do anything more complex than rock-paper-scissors in Haskell will likely fry your brain.

    Captha: jumentum - like momentum but younger

  • (cs) in reply to Raniz
    Raniz:
    Kalle:
    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).
    Not trying to start a functional-programming-vs-everything-else flame war here, but coming from an imperative/OO language and trying to do anything more complex than rock-paper-scissors in Haskell will likely fry your brain.

    Captha: jumentum - like momentum but younger

    Am I the only one who sees OOP itself as declarative (even though method definitions are imperative)?

  • Meep (unregistered) in reply to Nagesh
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.

    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.

  • Bit Head (unregistered) in reply to Mcoder
    Mcoder:
    Good documentation is overrated.
    Huh? Did you mean to say underrated? Or is my sarcasm detector just broken today?
  • (cs) in reply to hoodaticus
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    First time in my entire life, I had more than 6 big beers at one single sitting.

  • C-Octothorpe (unregistered) in reply to Nagesh
    Nagesh:
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    First time in my entire life, I had more than 6 big beers at one single sitting.

    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?

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    Nagesh:
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    First time in my entire life, I had more than 6 big beers at one single sitting.

    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?

    Just you, bud. Most of us wait till evening and/or when they've quit work for the day.

  • C-Octothorpe (unregistered) in reply to Matt Westwood
    Matt Westwood:
    C-Octothorpe:
    Nagesh:
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    First time in my entire life, I had more than 6 big beers at one single sitting.

    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?

    Just you, bud. Most of us wait till evening and/or when they've quit work for the day.

    Ahh, good to know I have someone to drive me home from work today... Thanks!

  • Just Me (unregistered) in reply to Eisentein
    Eisentein:
    kadal:
    Some equality are more equal than others

    x = y // "y" is assigned to "x" x == y // "y" is logically equivalent to "x", can convert types if required x === y // "y" is identical to "x", no conversion of types allowed x ==== y // "y" is composed of the same electrons as "x" x ===== y // "y" ==== "x" and across all space/time continua

    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

  • Fedaykin (unregistered) in reply to Raniz

    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.

  • Nagesh 2.0 (unregistered) in reply to hoodaticus
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    Nagesh has been whining about your "racist" comments about his taxi and brown skin.

    Carry on. 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!

    Are you still hungover from celebrating the world cup or something?

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    Matt Westwood:
    C-Octothorpe:
    Nagesh:
    hoodaticus:
    Nagesh:
    boog:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.
    Nice try Nagesh-old-buddy, but the article doesn't appear to have anything to do with RDBMS.

    Keep on trollin!

    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!

    Are you still hungover from celebrating the world cup or something?

    First time in my entire life, I had more than 6 big beers at one single sitting.

    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?

    Just you, bud. Most of us wait till evening and/or when they've quit work for the day.

    Ahh, good to know I have someone to drive me home from work today... Thanks!

    No worries but if you puke up on the seat covers you're a dead man.

  • WTF (unregistered)

    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 :-)

  • (cs) in reply to Meep
    Meep:
    Nagesh:
    In my point of view, NULLS are completely useless and stupid. Whoever came with NuLL concept need to be drawn, quartered and then left to rot on the pikes of the RDBMS compound.

    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.

    <span style="color:"white";">Great comment!

  • (cs) in reply to boog
    boog:
    Nagesh:
    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!
    At least you can sleep easy knowing bogger will never even come close to stealing your "Number One" title.

    But "number one" is frits!

  • name (unregistered)

    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.

  • Two Deep (unregistered) in reply to ExpatEgghead

    In all my years of coding, the terribleness here is unequalled.

  • (cs) in reply to Magnus
    Magnus:
    No WTFs here, move along.

    As others have pointed out: for floats, you need an epsilon. Either you put it in a common function like here, or you put it in every single compare (which would not be fun to maintain).

    if((obj1 != NULL) && (obj2 != NULL) && Math.abs(obj2 - obj1) < EPSILON) doStuff();

  • blarg (unregistered)

    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...

  • (cs) in reply to lolwtf

    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();

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

    As either the integer 18372 (or 183720 if you deal in hundred-thousandths of a dollar, etc) or the value 0.018372 represented by something more precise than floating-point.

  • (cs) in reply to name
    name:
    Anyone who thinks that 'double' thingie is bad just because they store money in it should have a look here: link here

    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.

    Again, what is matter with yuo people? I have fixed URL.

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

    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.

  • ÃÆâ€℠(unregistered)

    This has Nagesh written all over it.

  • ÃÆâ€℠(unregistered)

    This has Nagesh written all over it.

Leave a comment on “The Qualities of Equality”

Log In or post as a guest

Replying to comment #:

« Return to Article