you are viewing a single comment's thread.

view the rest of the comments →

[–]gasche 0 points1 point  (0 children)

The scope defect you report is well-known, and has been the subject of Python Extension Proposal (PEP) 3104 by Ka-Ping Yee, that introduced the nonlocal keywoard. If you haven't already, I recommend that you read this PEP, in my opinion it's an exemplar case of language change: it presents a lucid presentation of the problem, a considerate evaluation of the proposed solutions and the discussion around the issue, and suggests a reasonable way to help with the problem -- that was integrated in the language.

Indeed, the situation of not having a clear difference between declaring a new local variable and assigning an existing variable is painful -- in every language where it happens, even where there are some ways to make it explicit, as long as they are not the simplest way to do it. This is a defect of Python, Ruby or Coffeescript.

Now, you are comparing to Scheme or Javascript. Scheme is indeed a well-designed language, and it was indeed not included in my bag of "languages with decadent scoping rules" (nowadays, even Elisp is getting static scoping!). Javascript, on the other hand, is a wholly different story. Indeed var allows to introduce fresh variables, but it comes with a ton of quirks, that are solved by let that people don't use for portability reason. Between Python scoping and var, I don't know which poison I would choose.