DIP4: Properties

Leandro Lucarella llucax at gmail.com
Sat Jul 25 10:46:21 PDT 2009


Nick Sabalausky, el 24 de julio a las 00:39 me escribiste:
>  An alternate usage/definition syntax for properties.
> 
> http://prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP4
> 
> Note that there are a few parts marked NEED HELP, that could use assistance 
> from someone with more expertise in this than me.

After reading all the threads again, I think the best proposal is the
opGet_foo() / opSet_foo() for diferentiating functions and properties.
I think is the more D-ish solution.

I don't like the "_name" though, because it adds semantic infomation to
the identifier, maybe a more template-like syntax can be used:

class X
{

	private int _foo;
	public string _bar;

	long opGet(baz)() {
		return _foo + _bar.lenght;
	}

	void opSet(baz)(int x) {
		assert(x >= _bar.lenght);
		_foo = x - _bar.lenght;
	}

	void f() {
		auto b = baz; // opGet(baz)()
		b += 10;
		baz = b; // opSet(baz)()
	}

}

I used an example without trivial properties because... well, you just use
member variables for that. That's why I don't see real value in adding
default properties getter/setters. I don't see DRY as a real problem
either, for non-trivial properties.


-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
EL PRIMER MONITO DEL MILENIO...
	-- Crónica TV



More information about the Digitalmars-d mailing list