Why use @property in D?

d, properties

Solution

The reason they work without `@property` is because `@property` was added after they allowed the property method syntax. Adding `-property` to your DMD command line enforces use of `@property` annotation. It's not the default for backward compatibility reasons. Someday it will become the default (or so they say) so it's best to compile with `-property` to ensure you are annotating properly.

Problem

I figured out by trying that ``` struct PropertyTest { @property int x() { return val; } @property void x( int newVal ) { val = newVal; } void test() { int j; j = x; x = 5; } private: int val; } ``` does exactly the same when I leave the `@property` out. Everything compiles fine. What's the point then for declaring functions as `@property`? BTW, I'm using the dmd2 compiler.

Original source