• Hanneman (unregistered)

    _.isEqual("Frist","First")

  • (nodebb) in reply to Hanneman

    Yes

  • DFYX (unregistered)

    Hardly a WTF. We've seen the unnecessary if dozens of time.

    The rest could be the remains of some refactoring. At some point, areEqual probably contained custom logic that was replaced with lodash when it was introduced into the project. Changing hundreds or thousands of calls to areEqual all over the codebase would have been a lot of work (and maybe not even possible if this is public functionality in a library). Leaving an old API as an adapter to the new one is sensible in so many cases. Sure, it should be annotated as deprecated but that's about it.

  • The Mole (unregistered)

    Its also useful for debugging purposes, you can put a break point on the return true or return false as appropriate, it can be hard to debug an equals in a complex if statement.

  • Tim Ward (unregistered)

    The if is nonsense, but having a wrapper for an external library is often not nonsense, eg if you don't want your code base littered with hard-to-change external references when the time comes to change libraries (again).

  • Red Five (unregistered)

    Testing whether something isEqual to something_else is just as grammatically correct as whether 2 values areEqual.

  • Naomi (unregistered)

    Given that functions are data in JavaScript, we could even shorten that by export const areEqual = _.isEqual.

    Not necessarily! Consider the following...

    "use strict";
    function Foo() {}
    Foo.prototype.bar = function() { console.log(this.toString()); }
    var foo = new Foo();
    foo.bar(); // [object Object]
    var foobar = foo.bar;
    foobar(); // TypeError: this is undefined
    

    In other words, Javascript won't bind the this value unless you immediately call the function (as opposed to, say, Python where you get the expected behavior). Now, maybe lodash refers to itself as _ instead of this, but it's not something you should rely on in the general case, like the article implies.

    For an extra bonus WTF, try running that code snippet without the "use strict"; pragma. And then realize that window is the holder for all global variables...

  • Prime Mover (unregistered) in reply to Red Five

    No it's not. Now if you were to call it .isEqualTo, then maybe I would concede.

  • Prime Mover (unregistered)

    I'm reminded of a new joiner who was apparently an English major who joined a team as a programmer, and didn't last the first day because she kept insisting that:

    someFunction("literal string", parameter)

    was grammatically incorrect, and it should have been written:

    someFunction("literal string," parameter)

    and went round changing it whenever she saw it and then complained that the code didn't compile, and they needed to get a new C compiler which didn't have a bug in it.

  • Doug (unregistered)

    Why not just this?

    import { isEqual as areEqual } from lodash;

  • tbo (unregistered) in reply to Prime Mover

    That's funny. It's thanks to my background as a programmer that I dislike the fact that in American English, a period always goes inside a quote at the end of a sentence. Even when quoting a special term, the correct way is always to quote "like this." You never quote "like this". That second version is correct in British English, not American English. And the American version bothers me.

  • Bruce W (unregistered) in reply to Prime Mover

    someFunction("literal string", parameter) was grammatically incorrect, and it should have been written: someFunction("literal string," parameter)

    Ouch, my brain! The programmer side of my brain is laughing while the editor side of my brain is going, "she has a point."

  • (nodebb)

    And for all those pirates pirating software,

      Arrrrrr.equal(foo, bar) 

  • (nodebb) in reply to tbo

    It bothers me too and I'm American.

  • (nodebb)

    All WTFs areEqual(), but some areMoreEqual() than others.

  • JJ (unregistered) in reply to emurphy

    Fuzzy pig logic :-)

  • markm (unregistered)

    Apparently anyone who claims to be the authority on English usage has a minimum required amount of irrationality. American editors irrationally place the ending quote mark to include punctuation that is not part of the quote. British editors irrationally retain an extra "u" in words like "color".

    And many editors on both sides of the Atlantic try to force Latin grammar into English, with rules on split infinitives and "ending a sentence with a preposition." (That last one would not be right even if moving the preposition to somewhere after the object was not a normal English construction - as shown in countless jokes where someone responds to criticism about this by adding "you a**hole" to the end of the same sentence.)

  • (nodebb) in reply to tbo

    It's even funnier because the convention of putting the final punctuation inside the quotes instead of outside hasn't any grammatical basis because it's a rule from typesetting as back in the day it made kerning easier.

  • Naomi (unregistered) in reply to markm

    And many editors on both sides of the Atlantic try to force Latin grammar into English, with rules on split infinitives and "ending a sentence with a preposition."

    Such rules are the sort of pedantic nonsense up with which one should not put!

  • (nodebb) in reply to markm

    The u in colour is irrational and extra? I guess it depends on pronunciation, in which case the American spelling (at least for southerners) would be "carlerr", and in Niw Zillund perhaps "killeh".

    I noticed the Australian Siri giving navigation instructions pronounces "onto" as "onter" :-D

  • Phil (unregistered)

    The real WTF, (at least if you didn't know about it, in which case it's awesome), is that in some languages "!=" isn't always defined as the opposite of "==". So two objects can be both equal and not equal, or not equal and not-not equal. Which is why if you define isEqual, you'd better define isn'tEqual too.

  • RLB (unregistered) in reply to markm

    Apparently anyone who claims to be the authority on English usage has a minimum required amount of irrationality. American editors irrationally place the ending quote mark to include punctuation that is not part of the quote. British editors irrationally retain an extra "u" in words like "color".

    It's not extra. English got the word from Anglo-Norman or French, not directly from Latin. Ditto for -ise vs. -ize, which is one of the few things the OED gets wrong.

  • doubtingposter (unregistered) in reply to RLB

    OKAY.

  • MiserableOldGit (unregistered)
    Ditto for -ise vs. -ize, which is one of the few things the OED gets wrong.

    Common usage trumps etymological exactitudes so it's not exactly wrong. Although I suppose we could question whether it's common usage, when i worked for a certain UK ministry they would reject publications, reports etc using the -ize form as being in American rather than British English.

  • (nodebb) in reply to cellocgw

    Unfortunately Arrrrrr be not a verb in Pirate; you be looking for be.equal().

  • (nodebb) in reply to RLB

    Ditto for -ise vs. -ize, which is one of the few things the OED gets wrong.

    I advise you to advertise a tolerance for -ise endings.

    Except for "burglarize", which is simply an abomination.

Leave a comment on “Is We Equal?”

Log In or post as a guest

Replying to comment #:

« Return to Article