News for hackers. Stuff that matters.
Re:Rust and Go by burntsushi on Saturday November 08, 2014 @07:30AM (#8576665)
I'm aware. The presence of nonlocal and global still makes them broken to me, even if it's a result of how scoping works. Lua and Javascript both manage to have unbroken closures.
Re:Rust and Go by masklinn on Saturday November 08, 2014 @08:08AM (#8576754)
> Lua and Javascript both manage to have unbroken closures.

Because they use explicit local declaration (and implicitly declared variables are global in both)…

Re:Rust and Go by ufo on Saturday November 08, 2014 @11:48AM (#8577385)
Yes, and I would say that requiring explicit local declarations is the right thing to do. Having a "default" variable scope is very error prone (typos are treated as new variables and closures don't work right) but at least with "global by default" you can use a linter to enforce that all your globals are explicitly declared. In Python its impossible to do something similar.
Re:Rust and Go by masklinn on Monday November 10, 2014 @06:39AM (#8583026)
> Yes, and I would say that requiring explicit local declarations is the right thing to do.

And I could hardly agree more with that, I simply disagree that Python's closures remain broken, they're simply fixed within the constraints set by previous design decisions.

> at least with "global by default" you can use a linter to enforce that all your globals are explicitly declared

Still, there's really no excuse for global as default, there's no convenience justification and could just as easily be an error (more easily really)

Re:Rust and Go by burntsushi on Monday November 10, 2014 @07:36AM (#8583172)
> I simply disagree that Python's closures remain broken, they're simply fixed within the constraints set by previous design decisions.

The fact that I have to distinguish between `global`, `nonlocal` and `default` scope makes them broken. `nonlocal` is a hack.

Saying that it's a result of previous design decisions is a sound technical reason for why `nonlocal` is necessary to make closures work. But as an abstraction, at least, they are broken.

With that, I will concede that they are broken in two different ways between Python 2 and Python 3. This is IMO.