Just a thought: read-only fields

BCS ao at pathlink.com
Tue Aug 4 11:16:58 PDT 2009


Reply to Nick,

> It's been established in the recent epic-discussions on properties
> that one of the biggest uses for properties is to implement publically
> read-only (but privately-writable) fields. That got me thinking, why
> not actually have real publically read-only fields instead of merely
> emulating them with properties? They are, after all, a fairly common
> idiom.
> 
> // *Not* an actual syntax proposal, but just to get the idea across:
> 
> private @publicread int foo;
> 
> // The class sees it as "int", but everything else sees it as
> "const(int)" // ...or something like that...
> 

how about this for a syntax:

private int i;
alias public const i;





More information about the Digitalmars-d mailing list