Live data from Hacker News

Nerdsniping: A glimpse into a stubborn mind

blog.andyet.com

91–94 of 94 posts

Re: Nerdsniping: A glimpse into a stubborn mind

#91

And this is why Javascript can be such an awful language. Leaving off a single equals has such a profound effect, often without a new coder even realizing it while reading the code. Imagine what happens to your code when someone tries to write a function for its side effects similar to the example seen in the blog post. Then releases it in production for it to break in six months with a feature change.

>"And this is why Javascript can be such an awful language." To be fair, this is breaking Javascript and that is something you could do in other languages, for instance here is a similar version for C++: http://pastebin.com/seySfpku

> #define int INT

This makes it somewhat obvious that you can't change how basic types work in C++. On the other hand, JS's dynamicity makes for some interesting situations, as seen here. I wouldn't consider it "awful" but it's certainly a language with more "deep complexity" than appears at first glance.

Re: Nerdsniping: A glimpse into a stubborn mind

#92
post #84

This kind of abuse is also available in Python! In [3]: class TheObjectThatIsEqualToAnything(object): def __eq__(self, other): return True In [4]: x = TheObjectThatIsEqualToAnything() In [6]: x == 3 and x == 5 Out [6]: True

It's not necessarily abuse. I once had to code a dummy object that supported all arithmetic operations with normal numbers and had a special comparison logic that it is never equal to itself. Then you could test if something is a number or a dummy object by comparing it to itself.

Re: Nerdsniping: A glimpse into a stubborn mind

#93

And so far everyone has missed telling the poor OP how to avoid writing two equality checks... if( [80, 443].indexOf(port) !== -1 && http === false )

Are you certain that that's an improvement?

For two options, almost certainly not ;-)

For N ports, or for a port list defined from a config file however it could be. It's even nicer in python:

    ports = [80, 443, ...]
    if port in ports and http:
        ...
Or with underscore:

    var ports = [80, 443, ...];
    if(_(ports).contains(port) && http) {
        ...
    }
Good collections make it better than manually checking the return code or checking an explicit set of port values. Also configuration > magic_nums.

Re: Nerdsniping: A glimpse into a stubborn mind

#94
post #51

Earlier quoted context omitted.

Sure, but then it's obvious that you're doing something beyond an equality comparison.

Do you mean it is obvious to people who know objective C? I've never used the language, but its not obvious to me just from the other c-family languages I know.

Yes, if you know Objective-C. If you don't know it, I wouldn't expect you to immediately grasp anything about the behavior implied by a snippet of it.
Post reply on HN