On 17 March 2012 23:52, Manu <[email protected]> wrote: > On 17 March 2012 21:56, Walter Bright <[email protected]> wrote: > >> On 3/16/2012 7:11 AM, Manu wrote: >> >>> attribute myAttribute >>> { >>> this(int something); >>> >>> bool bNeedsAttention; >>> >>> property void refresh(bool bRefresh) { bNeedsAttention = bRefresh; } >>> } >>> >>> @myAttribute(10) int thing; >>> >>> thing.refresh = true; >>> >> >> Under the hood, where would that per-instance data be stored? >> >> Compile-time annotations can be stored internally to the compiler, but >> per-instance runtime data? How is it connected to the instance? When is it >> constructed and destroyed? >> > > In Java+C# it just lives in the class somewhere. Put it right beside the > attributed member, or maybe separate them into an attribute section at the > end of the class (to preserve structural layout). Construct along with the > class, I suppose the moment would be after member initialisation, but > before the constructor executes. > I wonder if it should only be allowed on classes/class members... adding > hidden data to a 'struct' almost defeats the purpose. Java doesn't have > 'struct', so no problem. I wonder what C# does exactly... >
I tend to think of 'struct's as 'passive', and compile-time annotations would provide me with every use case I can imagine for my own purposes in the case of structs. classes seem far more likely to need stateful attributes.
