5 ms·
Urg. Off topic, but I dislike this perl/ruby tendency of calling hash tables hashes. When I see the word hash, I always think of a value (ie a hash code) and no
by dkersten 14y ago
Urg. Off topic, but I dislike this perl/ruby tendency of calling hash tables hashes. When I see the word hash, I always think of a value (ie a hash code) and not a data structure. Why couldn't they call it a hash map, hash table, map, table, dictionary etc like all the other languages...?
- charlieok 14y agoI agree with that. 'map' or 'dictionary' are the best choices I think (or 'associative array', but why bring arrays into it). That's the interface, of which a hash table is just one possible implementation.
- Myrmornis 14y agoI've never liked 'dictionary'. The analogy isn't at all apparent to me. A dictionary explains what words means. The thing we're talking about doesn't explain what keys mean. (Someone who spends most of his time writing python here.) 'map' or 'mapping'.
- mmahemoff 14y agoI think dictionary is a useful high-level analogy. Small key objects mapping to potentially large, and often structured, value objects. (By structure, I mean the definition in a dictionary often includes fields like pronunciation and origin.)
- SoftwareMaven 14y agoA dictionary maps words to their definitions. The words are the keys, the definitions are the values. Seems reasonable to me. Though as another predominantly pythoner, I do prefer map as well.
- Myrmornis 14y agoIn a dictionary the value (meaning) is often (partially) implied by the key (word), by etymology etc. In the data structure there need be no relationship between the key and value other than the fact that they are a key-value pair in this instance. It introduces messy cultural concepts into what should be a clean, abstract concept.
- charlieok 14y agoIt's about the operations. One Does Not Simply (tm) read a dictionary. One instead performs a “lookup” for a particular item. The dictionary is designed to make this lookup fast and reliable, which matches the purpose of these data structures in software.
- aamar 14y agoSadly "map" is also the name of the critical "map" function which operates on lists. Maybe with an indefinite article ("a map") it's clear enough.
- dkersten 14y agoSure, so go the Lua route: table. Or the python route: dictionary. If neither of those do it for you, how about "mapping"? Hash (and hash map, hash table etc) leak too much implementation detail. What if you want a tree-based mapping instead? I like how in C++ it's map (for ordered, rb-tree based maps) and unordered_map (for unordered, hash table based maps).
- aamar 14y agoI'm going to try out "mapping" -- good suggestion.
- markov_twain 14y agoThis bit of ruby should take care of it HashMap = HashTable = Map = Table = Dictionary = Hash And if you're feeling adventurous, Object.send :remove_const, :Hash
- agscala 14y agoPlease never, ever do this
- DanWaterworth 14y agoIf doing this is such a bad idea then why is it so easy?
- jlgreco 14y agoIf doing: #define BEGIN { #define END } were such a bad idea, then why is it so easy?
- DanWaterworth 14y agoMaybe the language is poorly designed.
- jlgreco 14y agoOr maybe the connection between being able to do something and it being a good idea to do something is just in your head.
- DanWaterworth 14y agoIn my experience, making obviously bad things difficult or impossible improves reliability. This idea certainly resides within my cranial cavity, but that doesn't necessarily make it wrong.
- 14y ago
- grey-area 14y agoBecause the primitive is called Hash my %hash = (); Hash.new So naturally people talk of Hashes etc. I understand where you're coming from, but it's really not very important, and it would be more confusing to talk of Hash Tables as learners would naturally look for HashTable in the stdlib.
- oleganza 14y agoThat was the question: why the class is named Hash instead of HashMap or Dictionary? Was it done intentionally, or it is just an accident because someone did not know English very well?
- grey-area 14y agoI agree Map or Dictionary would have been fine too, but it's so widely used it needs to be easy to type so two words is not great (HashMap). However I suspect it was just named that way following perl (written by an english speaker). Obviously it's far to late to change it now and I can't say it bothers me or most Ruby users. It's something you get used to very quickly.
- dkersten 14y agoSo do what python did: dict Though even HashMap isn't bad because typing is a solved problem - with auto completion and touch typing two words really aren't an issue in my mind. People get used to living with all kinds of things, but that doesn't make them any better. Yes I'm aware that this applies equally to my typing comment as to you having got used to hash.
- Terretta 14y ago> why the class is named Hash instead of HashMap Why in golang is a function denoted by func instead of function? I'd guess it's because programmers prefer fewer keystrokes as long as the term remains sufficiently mnemonic.
- 14y ago
- draegtun 14y agoIt's because Larry Wall wanted something shorter than associative arrays. * http://www.nntp.perl.org/group/perl.perl6.language/2007/05/msg27646.html http://www.nntp.perl.org/group/perl.perl6.language/2007/05/m... * http://www.nntp.perl.org/group/perl.perl6.language/2007/06/msg27659.html http://www.nntp.perl.org/group/perl.perl6.language/2007/06/m...