class invariants and property declarations

Jonathan M Davis jmdavisProg at gmx.com
Thu Feb 17 10:48:23 PST 2011


On Thursday, February 17, 2011 10:39:20 Jesse Phillips wrote:
> Jonathan M Davis Wrote:
> > Except that @property is for _functions_. You mark a function with
> > @property so that it _acts_ like a variable. @property on a variable is
> > _meaningless_. It would be like marking a variable nothrow. It makes no
> > sense. Neither should be legal. The fact that a member variable is
> > public makes it a property. @property on a member variable makes no
> > sense.
> > 
> > - Jonathan M Davis
> 
> class Foo {
>     @property {
>            int min;
>            int hour() { return _hour;}
>           ...
>     }
> }
> 
> I agree that useless markings should usually be disallowed, but for me
> there is visual cues that @property provides and if I'm declaring a number
> of public fields/functions I'd want the present them in a similar manner.

Except that @property on a variable does _nothing_. It's totally inappropriate. 
I really think that it should be a bug. It wouldn't make any sense to mark a 
variable as nothrow would it? A public member variable is both a property and 
nothrow by its very nature.

Now, sadly enough, if you replace @property with nothrow in the code above (and 
remove the ... and make sure that there's actually an _hour variable), it 
compiles just fine, so the compiler is being ridiculously lax about attributes 
that aren't valid.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list