Revamping associative arrays

Piotrek starpit at tlen.pl
Mon Oct 19 12:40:27 PDT 2009


Bill Baxter pisze:
>>> Just get rid of the the one-argument foreach over AAs altogether and force
>>> the user to be
>>> explicit about it.
>> I wouldn't do so. Would anybody do an error by thinking that foreach
>> (elem,table) should iterate over keys?
> 
> Bearophile.  And anyone coming from python, at the least.  And anyone
> who agrees with the logic of connecting 'in' with what gets iterated.
> 

And only python that I am aware of. Java,C#,PHP (which hold most of all 
programmers) are defaulting to values unless explicitly stated.

>> Maybe I'm not thinking correctly but for me an assoc array is just an array
>> with additional key (index) features thanks to which I save space and/or
>> have more indexing method than only integers.
> 
> It can also be thought of as a set with some ancillary data associated
> with each element.  In that case the keys are the set elements, and
> the values are just some extra stuff hanging off the elements.
> 
> --bb

Sorry in advance, I couldn't resist.

 From Wikipedia:
"From the perspective of a computer programmer, an associative array can 
be viewed as a generalization of an array. While a regular array maps an 
index to an arbitrary data type such as integers, other primitive types, 
or even objects, an associative array's keys can be arbitrarily typed. 
The values of an associative array do not need to be the same type, 
although this is dependent on the programming language"

So it almost the same what I have said. I hadn't seen wiki entry before 
nor didn't changed the article's test ;) So now you can see that for 
most people (except Python guys and maybe a some more) it should behave 
like normal array. It's just intuitive.

What you are talking about it's a side effect of AAs (or rather 
derivative feature) and then we use the keys property or the key,value pair.

Cheers
Piotrek



More information about the Digitalmars-d mailing list