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

what scoping rules make javascript better than python for evented programming? I am not a big JS writer, but I can't seem to see anything important (nested functions, globals).

Maybe you are referring to the fact that JS has an arguably better syntax for anonymous functions?



Python has implicit declarations, which lead to a world of hurt because you can't directly modify variables in arbitrary scopes. Python 3 has nonlocal, but that only extends the number of function scopes you can refer to to three.

I think having implicit declarations is probably the worst mistake Python made. It just makes things so much more confusing.


Sorry, I made a mistake: nonlocal gives you as much power as usual closures. I still stand by my statement that implicit declarations make things very confusing.


In python nested functions must be declared before calling them. Also stuff like this seems to crop up on me when I ry using closures: http://stackoverflow.com/questions/2516652/scoping-problem-i...


that is what I meant as having a better syntax for anonymous functions. I agree it's bad (even with nonlocal in python 3) but that is not a matter of different scoping rules, it's only syntax.




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

Search: