in reply to "When closures capture their context" and "scope gotchas in Javascript"

This kind of scoping is why I swore off PHP too. I wrote quite a bit of code thinking I'd figure out how scoping rules worked later (I figured there must be a my I hadn't found out about yet). It turned out, though, that there were only three scopes: global, file, and function. I was horrified. It's been over a year, and I still cringe a little inside as I think about it.

  • Comment on Re: "When closures capture their context" and "scope gotchas in Javascript"

Replies are listed 'Best First'.
Re^2: "When closures capture their context" and "scope gotchas in Javascript"
by moritz (Cardinal) on Feb 08, 2008 at 16:57 UTC
    Speaking of other language woes - I intended to learn Lua, until I found out that variables are global by default, and you have to add a keyword to limit their scope to the current sub/method.

    That, and the fact that I couldn't find a use strict; equivalent made me jump back to perl immediately.

      Which happens to be the reason both tye and I have relegated Ruby to the "Neat Toy" category. If the compiler can't be enlisted to help you catch typos, then your language design is seriously flawed. (That and how does a language by a Japanese hacker go through 3 versions before an American adds support for UTF-8??)

      My criteria for good software:
      1. Does it work?
      2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
        how does a language by a Japanese hacker go through 3 versions before an American adds support for UTF-8?
        IIRC Unicode isn't nearly as popular in Asia as it is in, for instance, western Europe.

        Last I heard (some years ago) the Chinese really didn't like it since they already use some kind of encoding that differentiates certain "characters" that look /exactly/ the same but are pronounced differently (which is useful for speech generation), and at least back then the unicode standard did not distinguish between them.

      I intended to learn Lua, until I found out that variables are global by default, and you have to add a keyword to limit their scope to the current sub/method.
      That's true in Perl too if you don't use strict. Well, so in Perl the alternative is lexical scope which, as I know from certain other *ahem*VB*ahem* experience, is much better than subroutine scope for most purposes.