On 16/12/2025 21:40, Matthew Weier O'Phinney wrote:
I want block scoping; I have been bitten by accidental re-assignment within a block many times, and hate having to come up with an ever-so-slightly-different variable name to disambiguate. I don't care if it's this proposal or the "let" proposal in terms of how the engine handles it - but the syntax of "using (expression => $var)" isn't going to get my vote due to how easily it can be written incorrectly.


I want block scoping too. I don't think *either* of the current proposals achieves that elegantly.

Context Managers aren't even trying to achieve it. Block scoping of the context variable is a minor design detail which was added after the RFC was shared with the list. You could in theory write a Context Manager which took a value in its constructor and spat it out unchanged from its "enter" method, but it would be a weird and wasteful way to create a local variable.

The let() block proposal *is* about block scoping, but only for its own special kind of block. I am not convinced by the reasons given for using this unusual approach.

I would much rather we copy the precedent established by ALGOL 60 years ago, and have variable declarations as statements which can appear in the body of any block. In particular, I would probably just copy JavaScript: allow "let $foo;" and "let $foo=expression;" anywhere, and disallow use in the "temporal dead zone" between the start of the block and the declaration.


However, I would also like Context Managers; which are a separate feature, giving nice sugar for re-usable try-finally blocks.


--
Rowan Tommins
[IMSoP]

Reply via email to