4 ms·
lack of local scope, specifically, seems tied to Python's general lack of scoping beyond function contexts. Which is definitely a footgun for people coming from
by ledauphin 6y ago
lack of local scope, specifically, seems tied to Python's general lack of scoping beyond function contexts. Which is definitely a footgun for people coming from languages with full block scoping (which I strongly prefer), but at the same time I can see an argument for it making a lot of sense to most beginners to programming, who "look upward", see a name, and wonder why they don't have access to that name.
I agree about the unintuitive binding of names, though presumably the rationale is simply that any other approach would have introduced a significant amount of boilerplate. The only syntax I can think of would require a "bare as", e.g.:
FOUR_HUNDRED = 400
NOT_FOUND = 404
match code_and_val:
case (FOUR_HUNDRED, as x):
print(x) # FOUR_HUNDRED is not bound at all, but simply matched
case (NOT_FOUND as x, as y):
print(x, y) # prints 404, code_and_val[1]
which looks quite weird to a Python programmer, though in this case I suppose you could argue that explicit is better than implicit.
not sure why the `|` overloading is a big deal here? there's no other significantly useful meaning for it in this context. Can you be more specific?
- mumblemumble 6y agoRealistically, any practical argument for Python's lack of block scope is probably just sour grapes. The real reason, I'm guessing, is that it started out as a hobby project 30+ years ago, and that block scope is not something GvR personally felt was worth the effort to implement at the time. Followed by three decades of not wanting to do that particular breaking change, because doing so would be far more painful than anything that happened in Python 3.0.
- otabdeveloper4 6y ago> ...because doing so would be far more painful than anything that happened in Python 3.0 Is this really true? I don't think lack of block scope is ever used for anything but causing bugs.
- sep_field 6y agoCould do it the same way JS did it, with const and let keywords. Breaks nothing.