Why to have properties to sort or duplicate arrays ?

Bill Baxter dnewsgroup at billbaxter.com
Sun Jan 28 01:15:03 PST 2007


Pierre Renié wrote:
> I don't think there is a need to change the property concept. Just deprecate the properties 'sort', 'reverse' and 'dup', and create methods instead.


*All* functions and methods in D that take zero or 1 arguments act like 
properties.  So just making 'sort' a method wouldn't change the fact 
that:

      array.sort

would still be a valid expression that mutates the array.  It would just 
make it so that array.sort() would *also* be valid syntax.

[But I do agree that sort() should at least be valid syntax for those 
who don't want to write code that looks like the above.]

----------
import std.stdio;
void foo() {
    writefln("hey I think I'm a property")
}

void foo(int x) {
    writefln("I think I'm a property too. And now I should be ", x);
}

void main()
{
    foo;
    foo = 10;
}



More information about the Digitalmars-d mailing list