views:

244

answers:

14

I'm designing a programming language, so I've been putting a lot of thought into the way base types are named.

"Dictionary" seems like a bad name for what dictionaries do. They aren't organized lists of words with their definitions; they don't deal with words, they don't with definitions, and they aren't lists. The only vague association they have with the word "dictionary" is that one performs "lookups" just as one does with a paper dictionary (which is as good an argument for calling them "phone books").

"HashTable" describes an implementation which may change.

"Associative array" (from JavaScript) gets points because "associative" is a good adjective for what it does, but loses points because "array" also describes an implementation, and worse, describes it inaccurately.

"Key/value pair set" seems most accurate but it too long to be useful (do you really want to type "KeyValuePairSet" every time?).

If we call a "key/value pair" an "association" we get "AssociationSet". That to me is the best but doesn't jump out at me as the right answer yet; it's still long and "set" still feels a bit wrong. "AssociationList" is worse ("list" implies ordering, which isn't there). I briefly considered just "Associations" but that sounds more like something I would name an instance rather than the class. "RelationSet" and "PairSet" are shorter but less descriptive (neither captures the fact that it's sort of a one-way relationship key to value; value to key is not meaningful within the context of dictionaries).

Any ideas what a better name for dictionaries might be?

+18  A: 

"Map"?

You're mapping one value to another.

a paid nerd
That was my other thought :-)
Preet Sangha
Yeah, I'd vote for "map" as well -- except that if you're planning to implement any kind of functional features in your language, "map" already has a well-defined meaning in that space. However, you might want to do like Haskell and have `map` function but also a `Data.Map` type.
Daniel Pryden
Yeah, that's pretty good. I thought of "HashMap" before but dismissed the idea because of the same issue as "HashTable", but I never considered separating out "Map". Still, map has its own problems (it evokes cartography) but I think this is the best solution so far.
Imagist
@Daniel Ouch, that is a problem...
Imagist
...perhaps "Mapping"?
Imagist
Imagist: Everything is a mapping. A class file is a mapping of methods and properties to a class. No matter what language I'm in I call this thing a 'HashMap', and it's what I will continue to call it until I die. There really is no decision to make here; call it a HashMap and be done. It speaks to the implementation, but *thats the point*.
Noon Silk
Silky, the point is to describe what the object does. Implementations may completely change, but the interface for the most part will maintain reverse compatibility.
Imagist
"Map" implies any type can be used as a key. "Dictionary" implies only strings can be used as keys.
outis
@outis. The .NET Dictionary type can use anything as a key.
Joren
A: 

Essentially they are lists with a key indexer. You could call then KeyValuePairCollection.

Preet Sangha
Which is even more to type than "KeyValuePairSet".
APC
Which is still 4x longer than "map"
demoncodemonkey
+1  A: 

You mention that you don't want to use "hashtable" because that ties it to a given implementation. But is that necessarily a bad thing? People developing code will care if your dictionary-like language construct has hashtable-like performance characteristics, and simply calling it a hashtable is the clearest way to communicate that.

However, if you really are going to have a general interface and then specific implementations (like how Java has the Map interface and then implementations like HashMap and TreeMap), then I agree with a paid nerd that "Map" is probably the best choice.

Daniel Pryden
I agree totally that including the implementation of something in its name is not a bad thing and is even *good*. But a feature of my language is that it tries to abstract as much away as possible (to maximize possibilities for runtime optimizations). Other examples of this are `Text` (defaults to `String` but if you do a lot of concatenation it will switch to `Rope`) and `List` (`ArrayList` but will become a `LinkedList` if you append a lot).
Imagist
+1  A: 

Map is a good and precise name, as suggested by a paid nerd.

I also like the name Table, that Lua uses.

Nick D
+14  A: 

Dictionary is the standard computer science term. Complaining that a real world dictionary isn't the same as the abstract data type is like complaining that a "heap" isn't literally a disorganized pile of stuff or that a "queue" doesn't involve people waiting in line to buy tickets. Many/most computer science terms are analogies.

That said, two other reasonable terms are "map" (as it is a mapping from keys to values) and "table" (hence, "hash table", a table implemented with hashing).

Java actually uses the term "map" (as well as "dictionary" -- Map was added later when they realized dictionary should have been an interface, but since the name was already used they had to come up with a new name.)

"Table" has the disadvantage that it can easily be confused with the database term.

Laurence Gonsalves
A: 

Does "list" imply ordering? Not in the real world - shopping, list, to do list, laundry list.... None of those are ordered, they are just things written down as they occur to the list writer.

Inevitably any word you choose will collide with everyday usage and/or associations with specialist IT usage. So, if you really want a better word you'll need a fresh metaphor rather than trying to repurpose names from other languages. So how about Rack? Or IndexedBag? KeyPairStash?

APC
A: 

Maybe it's my Perl background, but I prefer hash. # See, the symbol looks like what a hash looks like. If you have a hash of hashes. Just my subjective 2 cents. <shrug>

[Edit]

Think of a plate hash. The good stuff, not the canned. With chunks of potatoes, onions, peppers, maybe some corned beef. At first glance it looks like a big mess of delicious random food. But you can name the parts, upon examination. It's a type, weather you poor ketchup on it or lay some eggs on it. Now think of a Martha Stewart tray of vegetables. Everything is a nice list of vegetables. You can dip it in the ranch or humus or pile it on the plate. Hell, you can take some of the tomatoes and put it in the hash.

These are types. It's a way of organizing data that suggests what to do with it, but is separate from it, IMHO.

A map seems to me more of an action than a type. Here's how to eat the food or better yet how the food gets to your mouth.

In the end, it's just a name.

Elizabeth Buckwalter
Yes, it is your Perl background. '#' in everyday use is more likely to mean "number" or "pounds" than "hash". "Hash", "splat", and "bang" are not the common names for '#', '*', and '!', so please don't invoke anything like Natural Law to justify calling what Perl creates with its '#' character by the name of that character. (Interesting to note, though, that what used to be called 'period' has become 'dot', mostly through the need to verbalize web URLs.)
Paul McGuire
@Paul - the common name depends on locale. In the UK '#' IS called hash. If you call it something else people don't understand. If you say 'pound' of course that means '£'.
g .
My problem with "hash" is that it's describing an implementation detail. What if the lookup were implemented as a binary tree which never even *considered* the hash of a value?
Jon Skeet
@g. - You silly Brits are always calling things by the wrong names! And what's up with all those extra 'u's you keep throwing into words like "color" and "favor"? What's next, going to McDonauld's for a burgeur?
Paul McGuire
@Paul Perl uses % to signify a hash. # signifies a comment. I was just pointing out that the symbol # looks like a hash table. Period ends a sentence, a dot does not. This has not changed. IP addresses came before URLs.
Elizabeth Buckwalter
Elizabeth, as Jon noted, that describes an implementation detail. Also I'm not sure what the `#` symbol has to do with this; most languages (mine included) don't require symbols to signify types in names.
Imagist
@Imagist I was being silly, because it was 2 o'clock in the morning. It was short, because I was answering on my iPhone. To elaborate, the symbol not as an indicator of type but as a visual representation of how I think of hashes.
Elizabeth Buckwalter
@ElizabethB: Thanks, my Perl ignorance is showing once again. But I claim you threw me off with your original comment, so please be more careful when posting at 2 o'clock in the morning from now on. :)
Paul McGuire
A: 

i feel that i woud choose something "Index" or "KeyedIndex", "KeyIndex"...

edit: haha DIYIndex! or maybe im getting the whole idea about dict's wrong?

Oscar
A: 

In Python, dictionaries are officially the one and only example of mappings.

It's not hard to see that one may argue about what is reasonable to call "mapping", e.g. a function, in mathematics, is always a mapping. I'd imagine that we could call anything with a __getitem__() a mapping, which would also include sequence types, such as list.

However, note that there is an official definition (emphasis mine):

mapping: A container object (such as dict) which supports arbitrary key lookups using the special method __getitem__().

So, to answer your question, I would suggest either mapping or map.

ilya n.
A: 

As I understand the jinx is ...there is something ASSOCIATIVE in nature which has KEY VALUE relationshiop and we are looking for the word that brings out the same SENSE....so If were to word it I would call it AssociateKVMap ....but doesnt sound so cool ....so lets get more options i guess

+2  A: 

The only vague association they have with the word "dictionary" is that one performs "lookups" just as one does with a paper dictionary (which is as good an argument for calling them "phone books").

How about lookup?

Paul McGuire
+2  A: 

Map and hash have other meanings as well, which is slightly muddling.

I'm trying to think what you would call something like this in real life. Suppose you had a million movies to key and organize. You might find a specific movie's location by looking it up in the catalog or database. Libraries also use catalogs to organize books. Though there still may be some confusion with other uses of the term in computer science, just like table ( http://en.wikipedia.org/wiki/Database%5Fcatalog ), I think catalog or catalogue is an accurate and expressive term for a lookup table.

nnyby
A: 

Good imho.

Assoc
Array
Dict
Hash
Index
KeyValue
Map
Table

Bad imho.

NSMutableDictionary
hash_map
neoneye
Reasons? Your groups appear completely arbitrary.
Konrad Rudolph
You are correct. I would be ok with coding using the language in the top list. I make use of c++ and objc and thus bump into NSMutableDictionay and hash_map from time to time. Shorter names prefered, but not analysed it enough to say I have a favorite name.
neoneye
+1  A: 

AssociationCloud

MapCloud

Cloud because it is unordered. Nebulous.

Alex Baranosky