3 ms·
This is really a minor point, but lots of people seem to hate function level scoping, including these guys. Having started out in languages with function level
by hyperpape 14y ago
This is really a minor point, but lots of people seem to hate function level scoping, including these guys. Having started out in languages with function level scoping, and only later used block level scoping, the former strikes me as the most ordinary thing in the world.
Am I missing some compelling advantage of block level scopes, or is it just a matter of taste/familiarity?
- codexon 14y agoIf your functions get big, you will start getting naming collisions and bugs.
- trhtrsh 14y agoThat's a sign your functions are too big.
- trhtrsh 14y agoIt's deeply aesthetically offensive, for one. It's error-prone, for two: if False: p = 1 print p No, thank you.
- reissbaker 14y agoThat's not how function-level scoping works in Javascript. function p() { if(false) var p = 10; return p; } p(); // evaluates to undefined What you'd get in a block-scoped language is some sort of ReferenceError; you still don't get 10 in JS, though. The variable is accessible outside of the block, but the block itself isn't executed. The above is just equivalent to the following transformation: function p() { var p; if(false) p = 10; return p; } p(); Aesthetic offense is a matter of taste. I prefer Scheme over C for aesthetic beauty, but many prefer the opposite.