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

Steven Schveighoffer schveiguy at yahoo.com
Mon Jul 12 09:53:57 PDT 2010


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.

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.

dup and idup have problems as builtins also, see this bug:  
http://d.puremagic.com/issues/show_bug.cgi?id=3550.  But that's not  
because they are propertites.  I personally don't think they should be  
properties, but that's open to interpretation.

The only one I see there that is truly a property is keys.

-Steve


More information about the Digitalmars-d mailing list