Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



"everything you do is global, unless you know better"

That is not the JavaScript model at all.


He 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.


var is not extra in JavaScript the way nonlocal is in Python. var is a language construct that any good JavaScript program must use.


The point of the linked article is that this is not the CoffeeScript way at all (although the author wishes it was).


'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!"


Yes explicit is best and in Perl its very clear what you want...

  my $x = 10;


No, 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.


No, 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.


Functions define scope. The end. Not hard. One rule.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: