Hacker News new | past | comments | ask | show | jobs | submit login

How many sane languages have function scope rules? Python has them, that's one. Javascript is a mess but might count. PHP is not sane at all. Most other things have block scope as far as I know.



Many languages have block scope, but not all.

Python, Ruby, and PHP have function scope, but idiomatic Ruby guarantees block scope for loops. In Python even list comprehensions leak scope.

JavaScript has function scope but has the `var` keyword for local scope. Lua has global scope but has a `local` keyword as well.

As I mentioned before, however, I was referring to developers principally familiar with Python (or at least dynamic, interpreted languages) coming to Go, since that is the basis of the article.


Yes, it's a good thing to mention for python devs, but I don't know if it's necessary in any other context.

Also your wording about javascript is weird. 'var' for scoping is function scope, what is your 'but' for? And proper lua doesn't use globals for temporary variables, it's firmly in the 'block scope' camp.


Yes, it's a good thing to mention for python devs, but I don't know if it's necessary in any other context.

The article's title is "What Python developers need to know before migrating to Go". I don't know how many times I need to repeat this. I can't go back and edit the original post to clarify.

Anyway, about JS, you are right; I was thinking "var" was like "local" or "my", but it isn't. Oh well.


'let' is coming up for that purpose.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: