3 ms·
I think Python's is deliberately unexpressive, forcing you to use local variables pretty much everywhere. This tends to decouple stuff, which is usually good. T
by wisty 15y ago
I think Python's is deliberately unexpressive, forcing you to use local variables pretty much everywhere. This tends to decouple stuff, which is usually good. The model is "everything you do is local, unless you know better, and want to jump through a lot of hoops". Coffeescript works a similar way.
Javascript seems to have the model "everything you do is global, unless you know better".
I'm not a big Javascript hater, but this is one very sore point.
- swannodette 15y ago"everything you do is global, unless you know better" That is not the JavaScript model at all.
- lnanek 15y agoHe is talking about if you don't do anything extra (in this case, use the var keyword). Much like the nonlocal keyword in Python requires knowing about it and wanting to use it in order to actually use it and get the non-default behavior.
- swannodette 15y agovar is not extra in JavaScript the way nonlocal is in Python. var is a language construct that any good JavaScript program must use.
- Lazare 15y agoThe point of the linked article is that this is not the CoffeeScript way at all (although the author wishes it was).
- whateverer 15y agoNo, the Javascript model is "you name things with `var`, you mutate things with `=`". Python went for a more complicated scheme of having every variable in a function be a new binding when first assigned, and then it's just mutation (i.e. 'local'), unless explicitly declared to be nonlocal, but it still makes sense with their... penchant for mutable state. And Coffescript instead went over to PHP to have some of the glue it was eating.
- Someone 15y agoNo, the Javascript model is "you name things with `var`, you mutate things with `=`". If only it were that simple. It also has "you create thing with `var` and sometimes with `=`", plus it does not have block scope: if( true) { var x = 1; } // x == 1 here.
- ryanflorence 15y agoFunctions define scope. The end. Not hard. One rule.
- rayiner 15y ago'let' is a way to make things more local! When I say: let x = 0, I'm saying "hey, I don't care what 'x' is in other scopes, in this local scope it's 10, dammit!"
- draegtun 15y agoYes explicit is best and in Perl its very clear what you want... my $x = 10;