bye stable values, enter lazy constants
    Andrew Haley 
    aph-open at littlepinkcloud.com
       
    Thu Oct  2 09:50:16 UTC 2025
    
    
  
On 02/10/2025 09:17, Maurizio Cimadamore wrote:
> (Now, while I think it's useful to have static_classes_ inside a
> method, I think having a static field in there might be a bit confusing,
> as it looks like a local variable, but isn't really -- it's a field. So
> whether that's a good idea or not will have to be assessed separately)
static has worked that way in block scope in C++ for decades, and I 
don't think it causes any particular problems. Providing something like 
this would encourage people to use lazy constants in an idiomatic way 
rather than initializing everything up front.
 > If an exception is thrown while computing the value is never set on the
 > lazy constant -- meaning the next call to `get` will re-generate the
same exception.
This is what happens with block-scope static variables in C++. It does 
mean that the compiler inserts a hidden mutex whenever such variables 
are initialized, so implementation requires some thought.
-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
    
    
More information about the leyden-dev
mailing list