Why to have properties to sort or duplicate arrays ?
Pierre Renié
archlinuxien at gmail.com
Fri Feb 2 14:20:09 PST 2007
Daniel Giddings Wrote:
> if you make a method clean, it can act like a "property" even if it
> doesn't return anything as it is a syntax "shortcut" if you like:
>
> import std.stdio;
>
> class C
> {
> void clean()
> {
> writefln( "C.clean" );
> }
> }
>
> void main()
> {
> C c = new C;
> c.clean; // works, but is bad programming style
> // c.clean() has a clearer meaning
> }
>
> this doesn't mean you should remove this feature (or any other) because
> bad programming style or design obfuscates the meaning of the code.
Why not to add a keyword "prop" ?
Like in this code :
class C
{
void clean()//This is a method
{
writefln( "C.clean" );
}
prop int somevalue()//This is a property
{
return 1;
}
}
void main()
{
C c = new C;
c.clean; // won't work because there is no keyword "prop" (=> compile error)
c.clean(); //correct
int i = c.somevalue; // correct because this is a property
}
I want this because I want the compiler to prevent me from making mistakes.
More information about the Digitalmars-d
mailing list