How One Missing `var` Ruined our Launch
161–170 of 223 posts
Re: How One Missing `var` Ruined our Launch
#162Re: How One Missing `var` Ruined our Launch
#163Re: How One Missing `var` Ruined our Launch
#164Re: How One Missing `var` Ruined our Launch
#165Earlier 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.
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
#166Earlier 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 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
#167Earlier 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?
It's already implemented, you just have to enable it.
Re: How One Missing `var` Ruined our Launch
#168Ouch. 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.
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
#169Why 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 ;