Why is array.reverse a property and not a method?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Mon Jul 12 10:16:44 PDT 2010


On 07/12/2010 11:53 AM, Steven Schveighoffer wrote:
> On Mon, 12 Jul 2010 12:16:32 -0400, eris <jvburnes at gmail.com> wrote:
>
>> Just though I'd post here on something that made me question my sanity
>> late
>> one night.
>>
>> I was working on some test code and for some reason put parens around
>> "myArray.reverse". After that the compiler complained that "reverse"
>> was an
>> unknown identifier. It took me about 30 minutes at 2am to finally give
>> up and
>> figure out I needed sleep.
>>
>> The next morning after some google searching I noticed that everyone was
>> referring to the 'reverse' "property". That caught my eye. reverse
>> property?
>> Thats not a property, it's a method -- especially since it does an
>> in-place
>> modification of the object.
>>
>> This must mean it's something I don't understand. The only thing I could
>> think of is that the "reverse" property is actually a boolean which
>> tells the
>> iterator which direction to traverse the data structure.
>>
>> Your thought are appreciated.
>
> reverse, sort, dup, idup, keys, etc. are all "properties" that were
> present before genuine @properties were added to the language.

All of these antiquated built-ins should be moved into the library 
(either druntime or phobos).

> sort is all but deprecated, since std.algorithm.sort exists.
>
> reverse could even more easily be implemented as a library function than
> sort, it should be removed as well.

http://www.digitalmars.com/d/2.0/phobos/std_algorithm.html#reverse


Andrei


More information about the Digitalmars-d mailing list