Hacker News new | ask | show | jobs
by cursork 4529 days ago
> Explicit declaration of the scope of a variable at initialization leads to unintended global namespace pollution when omitting the declaration is legal and causes the variable to be placed in the global scope

Ah, but it's not legal with 'use strict;' (which everyone uses)

> That's because programmers who care about good syntax in their languages don't use Perl.

And Lisp has too many parentheses. I clearly just like my code to be illegible.

2 comments

Yeah - back when coffeescript was new this was an argument, but with "use strict", the likelihood of accidental mis-assignments is actually considerably slower in javascript than in coffeescript. In javascript you'll get an error assigning to a non-existant variable you meant to be global; in coffeescript you'll get a local varaible and that means subtly buggy code.
I think cursork was talking about 'use strict' in Perl; he said that everyone uses it. 'use strict' in JavaScript is much rarer than it is in Perl, at least in my experience.
Well, I always use it when I have the chance: it's easy to turn on, and it catches nasty bugs. Why wouldn't you turn it on? Even if you have a large legacy code base, it's still a a win, since you can turn it on function-by-function.
Additionally, unwanted global assignments are really easy to detect with a linter.