Earlier quoted context omitted.
> 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. on the other hand, those of us who have been around the block enough times have almost certainly encountered co-workers who were bright, talented, cute, whatever - but at the end of the day were just ... sloppy ... lazy ... careless ... in their approach. It's a persona…
"...never learned to by hyper-vigilant..." My eyebrow just raised so far my forehead cramped.
How One Missing `var` Ruined our Launch
101–110 of 223 posts
Re: How One Missing `var` Ruined our Launch
#102I'm not an expert in JavaScript... Given that you said that, and that the problem you hit is a common pitfall for Javascript developers (especially if you're not very seasoned with the language), I'd strongly recommend picking up a copy of Douglas Crockford's Javascript: The Good Parts . Not only does he inform readers of this particular gotcha, but he also elaborates on Javascript best practices and tools that other…
"use strict" is catching a lot more errors, though frustratingly enough, not until runtime.
Re: How One Missing `var` Ruined our Launch
#103I don't always write JavaScript (CoffeeScript FTW) but when I do I use JSLint (vim-jslint)...
Re: How One Missing `var` Ruined our Launch
#104Actually it is very easy to debug any javascript error. In IE there is a setting where you can uncheck the Disable Script debugging (Internet Explorer) and in the status bar you will see any javascript error. If you check the checkbox IE will not report any errors. In general during your development you should always uncheck the box.If you double click the javascript status this will exactly report the line number wh…
Re: How One Missing `var` Ruined our Launch
#105This is one of the reasons I like shared-nothing architecture where the only way to share or persist something is via explicit caching or database.
Re: How One Missing `var` Ruined our Launch
#106Reminds 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…
Re: How One Missing `var` Ruined our Launch
#107Am 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.
use v5.12;
in perl code enables strict, at least.Re: How One Missing `var` Ruined our Launch
#108Earlier quoted context omitted.
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.
It still conjures up variables out of thin air. sum = 0 for v in someList: smu += v print sum # prints 0, doh!
Can someone please implement strict mode for Node?
Re: How One Missing `var` Ruined our Launch
#109Reminds 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 that I understand what you're saying: This is one of the reasons I hate the "feature" in C++ and C99 that you can declare variables anywhere. If you stick to declaring all your variables in one place, it's much easier to notice when you've already used a variable name.
Between that, and using -Werror to ensure that warnings never get ignored, I find C99-style declare-anywhere quite useful. It helps me keep the scope of variables limited to the places that need them.
That said, I rarely use C99's ability to declare a variable in the middle of a block. I primarily use the C99 feature of declaring variables as part of a loop.
Re: How One Missing `var` Ruined our Launch
#110Why 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!"