Live data from Hacker News

How One Missing `var` Ruined our Launch

blog.meloncard.com

61–70 of 223 posts

Re: How One Missing `var` Ruined our Launch

#61

Do I understand this right -- global variables are shared across all requests in node.js? If so, that is an insane design.

Well, that's what global variable means, shared among all functions in the process. Since there's only one process to handle all requests, they can access the global variables.

All languages used in web server that don't spawn a new process for each request have the same feature.

Re: How One Missing `var` Ruined our Launch

#62
Welcome to ==== http://www.fashion-long-4biz.com == Air Jordan (1-24) shoes $35 UGG BOOT $50 Nike shox (R4, NZ, OZ, TL1, TL2, TL3) $35 Handbags ( Coach Lv fendi D&G) $35 T-shirts (polo, ed hardy, lacoste) $16 Jean (True Religion, ed hardy, coogi)$34 Sunglasses ( Oakey, coach, Gucci, Armaini)$15 New era cap $16 Bikini (Ed hardy, polo) $18 FREE SHIPPING http://www.fashion-long-4biz.com

Re: How One Missing `var` Ruined our Launch

#63
post #3

Am I right in thinking that the javascript /* "use strict" */ construct would have caught this mistake (just like it would have done for me in perl code)? Seems to me that some such feature is absolutely and utterly necessary in any environment where you're doing a lot of closure creation ..

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.

Re: How One Missing `var` Ruined our Launch

#64
post #44

Earlier quoted context omitted.

I wasn't initialising the x variable Do you mean s/initialising/declaring/, or am I just really confused?

Yes, sorry, I meant declaring. Wrote that post in a hurry as I headed out the door, I wasn't paying too much attention.

Hmm, so you wrote a careless typo while describing your "careless" coding? Not to be harsh, but maybe it's a hint?

Re: How One Missing `var` Ruined our Launch

#65
post #64
post #44

Earlier quoted context omitted.

Yes, sorry, I meant declaring. Wrote that post in a hurry as I headed out the door, I wasn't paying too much attention.

Hmm, so you wrote a careless typo while describing your "careless" coding? Not to be harsh, but maybe it's a hint?

Well if you really want to go into painful detail about it, I had originally phrased the sentence differently, something along the lines of "leaving out the var in the for loop initialisation". It wasn't very readable so I changed it, but the word 'initialise' was on my mind.

In any case, I'm not sure that I need a hint to tell me that doing things quickly and carelessly is a bad idea. But we all do it sometimes, in both our programming and our writing.

Re: How One Missing `var` Ruined our Launch

#66
post #24
post #22

> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line. jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.

Even better is setting your editor to run JSHint when you save a .js file, and let you know if there are problems. Not only does it avoid stupid bugs, it saves time round-tripping to the browser for trivial issues like syntax errors.

Never heard of JSHint. Thanks for the tip!

Re: How One Missing `var` Ruined our Launch

#67
post #57

This is why I like both Scala and Coffeescript approaches. On Coffeescript vars are created for you, and on Scala, you can't not use it (you either use var or val, making it easy to change from re-assignable variables to final ones). Note that nowadays going to Coffeescript from Javascript is quite easy: http://js2coffee.org/

I don't know Coffeescript - does it implicitly create a local var when there is already a global with the same name?

CoffeeScript is a compiler, so obviously it doesn't know anything about your runtime. It declares variables in the scope they're first assigned in; so 'global.x = y' works, while 'global = {}' compiles to 'var global; global = {};'.

Re: How One Missing `var` Ruined our Launch

#68
post #64
post #44

Earlier quoted context omitted.

Yes, sorry, I meant declaring. Wrote that post in a hurry as I headed out the door, I wasn't paying too much attention.

Hmm, so you wrote a careless typo while describing your "careless" coding? Not to be harsh, but maybe it's a hint?

Not to sound harsh, followed by something quite sarcastic and judgemental isn't a particularly nice way to address someone you don't know.

I for one would speculate, not to sound harsh, that if you haven't made silly errors like this then you haven't been around the block enough times.

Re: How One Missing `var` Ruined our Launch

#69
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 ;

Python doesn't let you write outside of local scope without a special keyword. Exactly the inverse of JS. If you want to write to global state, and you're aware that you're writing to global state, then you use the "global" keyword. That's all.
Post reply on HN