Live data from Hacker News

How One Missing `var` Ruined our Launch

blog.meloncard.com

161–170 of 223 posts

Re: How One Missing `var` Ruined our Launch

#162
I know there seem to be a few HN readers religiously against using an IDE, but in this case an IDE would have probably helped. Since it colors global and local variables differently the error would be much more apparent at the time when it was made (you typically have very few global variables so they stand out color wise).

Re: How One Missing `var` Ruined our Launch

#163
Exactly why we moved to CoffeeScript, without it you need to rigorously enforce coding conventions. This entails watching for missing vars, using jslint, having a script that searches for accidentally declared globals, only declaring vars at the top of a function, among other best practices. With CS you get all of that just by using it. If you can write high-standard code using a simpler, terser syntax, why avoid it?

Re: How One Missing `var` Ruined our Launch

#165
post #63

Earlier quoted context omitted.

Yeah, that's all he needed. Making it a comment isn't necessary either. Maybe Node should be strict by default? I can understand it not being the case for browsers that need to support legacy code, but for Node it doesn't really need to care about that.

Huh. On the scale from pragmatic idiosyncrasy to simply bizarre, making a string literal expression change the runtime behaviour in that manner is fairly wide towards the bizarre end of the scale. I think, if anything, requiring it to be in a comment would have been less odd; at least comments imply a sense of "meta"-ness.

> On the scale from pragmatic idiosyncrasy to simply bizarre, making a string literal expression change the runtime behaviour in that manner is fairly wide towards the bizarre end of the scale.

Yes, on the other hand it's quite necessary to not have non-compliant browsers blow up. `"use strict";` is just a noop in e.g. IE6. `use strict;` would be an error in it.

> I think, if anything, requiring it to be in a comment would have been less odd; at least comments imply a sense of "meta"-ness.

Javascript compressors definitely strip comments. They probably don't strip strings.

Re: How One Missing `var` Ruined our Launch

#166

Earlier quoted context omitted.

My theory is that most of the offending language designers looked at variable declaration in languages with static typing and thought "Wait, we don't have static types, so there's no reason to declare variables!"

Personally, I like the opposite solution, used in functional languages: "Wait, we don't allow changing variables once created, so we only need to support variable initialization with a value, not reassignment of a variable or declaration without initialization!"

> used in functional languages

Used in some. Haskell and OCaml mandate scope binding (unless you're at the top level of a module). Erlang does single-assignment (really pattern matches aliasing, an extremely limited version of Prolog's unification) without scope declaration, but what other FP languages do that?

Re: How One Missing `var` Ruined our Launch

#167
post #108

Earlier quoted context omitted.

It still conjures up variables out of thin air. sum = 0 for v in someList: smu += v print sum # prints 0, doh!

Exactly. The claim is that implicit local variables are less dangerous than implicit global variables. I've been bitten badly by both. Perl was the worst, where implicit variables were scoped differently according to Larry's philosophy when he implemented it. All for the sake of brevity. Can someone please implement strict mode for Node?

> Can someone please implement strict mode for Node?

It's already implemented, you just have to enable it.

Re: How One Missing `var` Ruined our Launch

#168
post #20

Ouch. I always thought JS's global-variables-by-default schtick was it's worst crime, but I've never seen such terrible consequences for it up close before. Note to self: before products get to forbes, do some load testing. Even if I am using node, with its magic event loop of invulnerability.

As a rule, in js I declare every var at the top of the function (or globe) in one giant var statement just because of this. Still, it's easy to get lost in the moment and mess up just once. I used to think this was just the way things were but pair-programming/code-review and/or a language with better scoping rules would've prevented this from happening.

> Still, it's easy to get lost in the moment and mess up just once.

Get a better editor, and JSHint, and "use strict";

Implicitly declared globals can be statically checked, there is no reason not to.

Re: How One Missing `var` Ruined our Launch

#169
post #48

Why has it become popular for dynamic languages to conflate establishing a binding with assigning it a new value? Ruby, Python, and Javascript are all guilty of this. Scheme got it right sometime in the 1970's. (let ((x initial-value)) ; binding (set! x new-value)) ; assignment Or in infix syntax (Dylan): let x = initial-value ; x := new-value ;

"Why has it become popular" implies that it's a recent thing. Darmouth BASIC did the same things in the early 1960s.
Post reply on HN