Are associative arrays stable in D?

Ali Çehreli acehreli at yahoo.com
Wed Jul 17 10:52:06 PDT 2013


On 07/17/2013 10:21 AM, Yota wrote:

 > On Wednesday, 17 July 2013 at 09:48:06 UTC, monarch_dodra wrote:
 >> I find it disturbing that the built-in property "keys" would dup an
 >> entire array, and then copy all the keys into that array, whereas the
 >> function "byKeys()" will simply allow you to iterate on the keys.
 >>
 >> "keys" is in blatant violation of the "properties emulate members"
 >> mind-set.

It is not a violation when the property is a value type, say, an int 
that is calculated by the property function. Otherwise, what to return 
when the value does not exist as a member?

 > My sentiments exactly.  I feel it would also be more appropriate to name
 > it 'getKeys'.

I think the "get" prefix is overused. Contrary to popular guidelines, if 
a function returns a value (property or not), it is acceptable and 
usually more useful when the function name is a noun:

     cpu.temperature;

is more useful to me as opposed to

     cpu.getTemperature();

 > 'dup' and 'idup' are big offenders.

They are nothing compared to 'sort': :)

Ali



More information about the Digitalmars-d-learn mailing list