> On Sep 6, 2024, at 4:47 AM, Rowan Tommins [IMSoP] <imsop....@rwec.co.uk> 
> wrote:
> 
> On Fri, 6 Sep 2024, at 03:01, Mike Schinkel wrote:
>>> Block-scoping doesn't have to allow shadowing of names, 
>> 
>> How exactly would that work?  Are you suggesting to restrict the use of 
>> variable names to one per function but still allow for block scoping?
> 
> Yes. That's how C# works, for example - variables are scoped to the block 
> where they're declared, but each name declared must be unique, not shadowing 
> one that's currently in scope.

Interesting. That seems... an odd choice, just to enable block scoping.  

BTW, I find block scoping has more pain than pleasure, even when it is not 
exactly causing bugs, e.g.:

if (is_null($widget = getWidget())) {
   return;
}
echo $widget->name;  //  block-scoped $widget not available

The above would actually be a runtime bug in PHP, if the code were not covered 
by testing beforehand. In a statically-typed pre-compiled language like Go, it 
is just an annoyance.

OTOH, I very rarely ever find a situation where I am actually happy to have 
block scoping. IOW, I don't know what it enables that make people want it so 
badly, except possibly conflating closures with scoped-blocks, or ability to 
further control scoping in (too) long functions.

I think features that would reward people for writing shorter functions would 
be much better, but maybe that is just me.


>> Shadowing is not a feature that is added, it is the result 
>> of block scoping, AFAIK.
> 
> Shadowing is absolutely a feature that has to be implemented: the compiler 
> has to store some "backup" of the old name binding, so that it can be 
> "restored" when the shadowing variable goes out of scope. Without shadowing, 
> it's instead about tracking the "lifetime" of the variable, and refusing 
> references to it outside of the block where it's "live". I'm sure the 
> implementation of both versions varies wildly.

Meh, you can twist words to mean that, but your words ignore that all variable 
scoping is then explicitly implemented as feature. 

What I meant was the language already implements variable scoping so there is 
no additional work needed beyond what they language already implements. Unless 
the language was weirdly designed in such a way that it cannot reuse existing 
scoping mechanisms, which I will admit may actually be true of PHP.

OTOH, I am not speaking of what you just revealed about C# which I find to be 
also be, weird. 

> You're right, there is some value in letting people know that a feature would 
> be popular if implemented. I'm just aware that threads like this can quickly 
> grow into rambling discussions of wild ideas with little grounding in what's 
> possible, or back-and-forth debates between two people about something 
> completely hypothetical. When that happens, those with the experience to 
> actually implement big new features tend to tune out. 

With respect, local constants and/or immutable local variables are hardly "wild 
ideas," nor likely something that has "little grounding in what's possible."

-Mike

Reply via email to