5 ms·
How likely is this hypothetical cleanup of JavaScript to happen, though? It seems about as likely to me as the likelihood of Haskell replacing C++ or Java; i.e.
by tmhedberg 14y ago
How likely is this hypothetical cleanup of JavaScript to happen, though? It seems about as likely to me as the likelihood of Haskell replacing C++ or Java; i.e. not very likely at all (even though I share your opinion that it would be a wonderful thing if Haskell were more popular).
The main advantage that JavaScript seems to have over Python is multi-statement lambdas. In other respects it seems no more Haskell-esque than Python is. Python at least lets you do a very limited form of pattern matching on tuples. And JavaScript brings along so much hastily-designed ugliness that it seems like it would take ages to break free of its historical warts.
I'd personally be happy if some flavor of Scheme became the dynamic language du jour, though I realize I'm living in a fantasy world there.
- yummyfajitas 14y agoJavascript isn't Haskell-esque, it's scheme-esque. I didn't mean to imply it was a substitute for Haskell, merely that it's a better version of Python. Javascript also has proper closures, and it's support for event driven programming (admittedly, not part of the language) is also quite nice. [edit, since I can't reply. By proper closures, I mean this shouldn't happen: > x = 0 > def foo(): > x = x + 1 > print x > foo() UnboundLocalError: local variable 'x' referenced before assignment ]
- kibwen 14y agoWhen you say "proper closures", do you mean anonymous functions? I can't think of any other reason why Python's closures wouldn't be considered proper. EDIT: Interesting, I've never run into that behavior before. Looks like you'd have to explicitly mark that variable as global if you want to mutate it: x = 0 def foo(): global x x = x + 1 print x foo() However, after reading the rationale[1], I tend to agree with this requirement: "This isn't a bug; it's by design. Because there's an assignment to 'a' in the function 'y', 'a' is considered local to that function. (It doesn't matter where the assignment happens within the function; the presence of an assignment anywhere is enough to make 'a' local for the entirety of 'y'.)" [1] http://bugs.python.org/issue9049#msg108309 http://bugs.python.org/issue9049#msg108309
- yummyfajitas 14y agoYou don't necessarily have to mark it as global to mutate. Some more interesting behavior: class BoxedInt(object): def __init__(self, v): self.val = v x = BoxedInt(0) def foo(): x.val = x.val + 1 print x.val
- cdavid 14y agoThis is an annoying behaviour, but it is consistent with Python's design . It is not exactly caused by broken closure, rather by the object model of python, and how named are bounds to objects. While this does not make it less annoying, it explains why the difference between using x vs x.val is logical from python POV.
- sanxiyn 14y agoJavaScript will have limited pattern matching. (Better than Python's, because it allows both array patterns and object patterns.) http://wiki.ecmascript.org/doku.php?id=harmony:destructuring http://wiki.ecmascript.org/doku.php?id=harmony:destructuring