4 ms·
I really don't get all the JS scoping hate. Especially because its quite similar to Python in that they both have lexical scoping with functions introducing new
by jakear 9y ago
I really don't get all the JS scoping hate. Especially because its quite similar to Python in that they both have lexical scoping with functions introducing new scopes, and I rarely hear complaints about Python. I guess this scoping might be annoying to people coming from C-style background, but it's really not all that big of a deal. JS even has `let` now to allow blocks to introduce new scopes too.
- kec 9y agoThe problem (as I see it anyway) is that function scoping + hoisting is weird and can cause some unexpected bugs.
- tomxor 9y agoOnce you learn that fact, and then avoid ever using function name() {} definitions, you will never have the problem of confusing hoisting actually happen to you... Yes var had it's own set of problems (which you could argue make the alternative of assigning functions to variables bad) causing unexpected bugs but those have in turn been solved very well by const and let... and just like function names, there is also no reason to use var now.
- haskellandchill 9y agoPython is awful. Since you haven’t heard any complaints. Maybe 3 is ok, can’t use it don’t know. Have to use 2.7 at work. Can’t make jars for Spark with Python and yes I am salty about it. Meanwhile we are on Ruby 2.5.1 because they didn’t fork the whole ecosystem with a language upgrade.
- chc 9y agoRuby's 1.9/2.0 upgrade had pretty similar changes to Python 3. For example, in Ruby 1.8.7, 'hello'[1] returned 101, whereas now it returns 'e', and String#each doesn't even exist anymore. Similarly, string encodings became significant in both Ruby and Python's breaking changes. It seemed to me like the Ruby ecosystem just didn't drag its feet as much as Python's (probably largely because Rails had enough pull to drag the Ruby ecosystem along with it, and Rails enthusiastically supported Ruby 2).
- mxyzptlk 9y agoMatz didn't change puts. It seems trivial, but I suspect making print a statement again would do a lot to speed up the Python3 adoption rate.
- maoistinquisitr 9y agoPython and JS are both equally awful. The sad reality is that Perl 5 still remains the only viable scripting language aside from scheme (lol) with sane scoping and lexical closures.
- lizmat 9y agoI think you will find that Perl 6 is even more sane in that respect.
- Scarbutt 9y agoI don't think 'let' existed when this article was written.
- tomxor 9y agoYour observation is undeservedly sitting at the bottom of this thread :P but it is quite an important one: In the authors comparison of the language features the relatively new `let` feature would now move one of the scheme features into the "shared with JS" subset, making it overall look a lot more like scheme... I suspect there are some other new shared aspects as well but I don't comprehend the language feature definitions well enough to say confidently.
- TheCoelacanth 9y agoI don't like the function level scoping, but I could probably get over it. Hoisting variable definitions is just straight up pants on head stupid. The way scoping for `this` works is bizarre and un-intuitive. I routinely run into people who spend a lot of time programming in JS and who I consider pretty smart and capable programmers (based on reviewing dozens/hundreds of PRs from them) who didn't understand the way it works until after I explained it to them. let/const/arrow functions fix most of these, but it took over twenty years for those problems to get fixed. Also, they didn't exist when this article was written in 2013.