Live data from Hacker News

How One Missing `var` Ruined our Launch

blog.meloncard.com

51–60 of 223 posts

Re: How One Missing `var` Ruined our Launch

#51

"Now is the point I’d like you to say: you should have used CoffeeScript, and hey TameJS while you’re at it. You’d be right." Perfect example of a developer hating JS just because he/she didn't bother to learn it first and got burned.

It's still very easy to miss a 'var', even if you know the language. Especially if you've just context-switched from ruby or python.

Re: How One Missing `var` Ruined our Launch

#52

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

Node is single-threaded, so yes they are shared. Requests are basically just multiplexed inside the same message loop.

In my opinion it wouldn't be quite as scary if js didn't make it so damn simple to accidentally define a global variable (like in this instance, where it was never actually declared in globally-scoped code).

Re: How One Missing `var` Ruined our Launch

#53

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

Global variables are basically instance variables on the process itself. They're going to be shared across all requests in all environments that handle more than a single request per process. If they had different semantics, they wouldn't really be what normal people call "global variables", would they?

So you just don't use them and everything's good. Which brings you to the real problem: JavaScript makes it distressingly easy to use a global variable where you meant to use a local one.

Re: How One Missing `var` Ruined our Launch

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

ALGOL '58 used := and = as distinct operators for assignment and equality in 1958.

https://en.wikipedia.org/wiki/ALGOL_58#ALGOL_58.27s_influenc...

Re: How One Missing `var` Ruined our Launch

#55
You can do some poor man's load testing very simply with siege (http://www.joedog.org/index/siege-home). Put a bunch of URLs in a text file, and run it with "siege -f urls.txt".

Of course it doesn't prove that your code is bug-free, but if you have concurrency issues, this will help shake them out. I've used this many times to reveal problems with DB connection pooling, concurrency issues, and excessive session size.

Re: How One Missing `var` Ruined our Launch

#56
> 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.

Sorry, that's incorrect. If you cannot fully simulate your environment for purposes of validation, you're not covering your bases.

Re: How One Missing `var` Ruined our Launch

#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?

Re: How One Missing `var` Ruined our Launch

#58
post #5

Reminds me of one of the more confusing bugs I've ever encountered in my life. I was throwing together a quick UI with Adobe Flex, and for some reason every time you clicked a particular button, the entire UI would shift 20 or so pixels to the right. I spent hours scratching my head until I noticed this for loop: for (x=0;x I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI…

Now there's an argument for syntax highlighting.

It also doesn't happen in languages where you must say self.x to access a property/field called x.

Re: How One Missing `var` Ruined our Launch

#59
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 ..

Running some variation of JSLint in his editor/IDE would likely have caught this, too.

Re: How One Missing `var` Ruined our Launch

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

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!"
Post reply on HN