@property - take it behind the woodshed and shoot it?

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 25 12:17:29 PST 2013


On Fri, Jan 25, 2013 at 09:06:44PM +0100, Johannes Pfau wrote:
> Am Fri, 25 Jan 2013 10:39:50 -0800
> schrieb "H. S. Teoh" <hsteoh at quickfur.ath.cx>:
> 
> 
> > - It's illegal to mark a function that takes 2 or more arguments as
> >   @property, because it makes no sense.
> > 
> 
> 3 or more arguments. UFCS properties have 2 arguments:
> 
> @property void age(Person p, int value); //OK, bad example, but you
> get the idea 
[...]

Good point, so it's 2 or more arguments for member functions, and 3 or
more for module-level functions.

Another thing I forgot to mention: once a function has been declared
@property, you cannot call it like a normal function anymore. So if you
declare at the module level:

	@property void age(Person p, int value);

then:

	void main() {
		Person p;
		//age(p, 123);	// Error: cannot call age like a normal function
		//p.age(123);	// ditto
		p.age = 123;	// OK
	}

The second case (p.age(123)) is valid only if age() returns a delegate.
Again, @property turns the function into a variable-like entity that
does not behave like a normal function to the outside world.


T

-- 
Lottery: tax on the stupid. -- Slashdotter


More information about the Digitalmars-d mailing list