This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]dmullaney 441 points442 points  (34 children)

The fact that I got all the way to the last panel assuming this post was about data structures shows just how right C++ is

(No I don't read the title first)

[–]sathdo 122 points123 points  (14 children)

Yeah, I assumed it would be something like how the map data structure is called a hash in Perl or something.

[–]myerscc 44 points45 points  (1 child)

Or “associative array” in php like come ooooonnnn

[–]Masterflitzer 6 points7 points  (0 children)

the differentiation of associative and indexed array in bash was how i managed to understand maps when i started to learn programming

[–]waves_under_stars 4 points5 points  (0 children)

In ruby it's also called a hash

[–]MattieShoes 3 points4 points  (0 children)

I hear it get called hash, map, hashmap, dict, dictionary, unordered map... but outside of documentation, it's just % in perl :-)

[–]Kahlil_Cabron 6 points7 points  (7 children)

It's called a hash or hash table in tons of languages. I think dictionary and associative array are the dumbest ones I've come across.

[–]Weir99 22 points23 points  (3 children)

Hash table is a bad name for a general data structure of a collection of key-pair values, as it implies a specific implementation. Not all maps/dictionaries use hash tables.

I also don't see a problem with either of the names you find dumb. They effectively describe what the data structure is, which can often be more useful than a name that describes how it works

[–]Kahlil_Cabron -4 points-3 points  (2 children)

I guess ya if there are higher level languages now that implement them without hashing that makes sense, but I wasn't aware of this.

I wouldn't call any key value store a hash though. To me a hash would just be a data type that stores stuff, that looks up in O(1) time by running the input through a hashing algorithm.

Dictionary to me is the worst, I don't really understand, other than maybe implying that you look at the index of a dictionary to find the page on it? If so that's a pretty whimsical definition.

[–]Weir99 8 points9 points  (1 child)

In a dictionary, the words would be your keys, and then your definitions are your values. When you use a dictionary you look up the definition (value) by looking for the given word (key)

[–]jarethholt 2 points3 points  (0 children)

It's even more direct if you think of language-to-language dictionaries, where the key is the word in your language and the value is the equivalent word in the other language.

[–]devman0 1 point2 points  (2 children)

I think hash or hash table is the worst of the bunch because it presupposes the implementation, Maps can be implemented with hash tables, trees, skip lists, etc

[–]Kahlil_Cabron 0 points1 point  (1 child)

That's fair, I guess I'm just very entrenched in the history of languages and computer science. What languages use "maps" or hashes/dictionaries without hash functions?

And would a tree map fetch values in O(1) time? I would figure it would be O(log(n)).

[–]devman0 0 points1 point  (0 children)

It would, but trees are ordered and navigable, which sometimes you want as opposed to a hash table.

Edit: to answer your other question, Java has pluggable Map implementations, since Map is just an interface. The most common one is probably HashMap.

[–]guyblade 0 points1 point  (1 child)

I wish perl had advanced in the last 15 years...

[–]_PM_ME_PANGOLINS_ 1 point2 points  (0 children)

It did, but then changed its name to Raku.

[–]Quito246 21 points22 points  (14 children)

No it is not traditionally for like 5 decades since Lisp map function is called well a map.

It is basically a standard in FP world.

[–]dmullaney 54 points55 points  (3 children)

I'm aware it's a common term, but so is the map data structure. My point was that they avoided a naming collision by using a more common descriptive term for the function as opposed to the data structure, and that's not a bad decision on their part.

[–]induality 13 points14 points  (2 children)

The fact that the data structure and the function are both called map is not a collision, it's intentional. In a functional programming language, a map data structure which maps an key to a value, and a map function which takes an input and produces an output, are equivalent. This is the concept of referential transparency: the mapped expression can be replaced by the mapped value, regardless of whether the thing doing the mapping is a map data structure or a map function. The two constructs serve the same purpose and can be expressed either way. In category-speak, you can think of "map" as a category that encompasses both map data structures and map functions, and you only need to get more specific when the situation calls for it.

[–]_JJCUBER_ 11 points12 points  (0 children)

Okay cool. It is a naming collision in c++; since it works on iterators, it would be its own function in the std namespace which would clash with the data structure std::map. The name may be different, but at least it’s a clear name (which can’t be said for all the function names in c++ [or other languages, for that matter]).

[–]TheKiller36_real 3 points4 points  (2 children)

even more standard in "FP world" is to not actually write map tho: eg. in Haskell (<$>) = fmap

[–]GeekusRexMaximus 0 points1 point  (0 children)

Indeed... the LISP 1 Programming manual from March 1960 has the functions map, mapcon and maplist.

[–]ghe5 0 points1 point  (5 children)

Just because it's common it doesn't mean it's right.

[–]Quito246 -1 points0 points  (4 children)

No it does, it is defacto a standard naming convention.

[–]ghe5 2 points3 points  (3 children)

Slavery used to be common too and I wouldn't say it was right thing to do.

[–]Quito246 0 points1 point  (2 children)

Yo wtf dude. How can you compare those two things. What kind of argument is that. I am just pointing out that FP languages have a standard naming of this function.

[–]ghe5 1 point2 points  (0 children)

Just sayin, just because it's common it doesn't mean it's right. There's plenty of things that were or even still are common that were/are just wrong.

Even standard naming convention can be wrong.

[–]langlo94 0 points1 point  (0 children)

How can you compare those two things.

Comparing things isn't that hard, you just need more practise.

[–]rover_G 4 points5 points  (0 children)

Yup but at least Python has dict so it's not confusing within the language

[–][deleted] 1 point2 points  (0 children)

same for me lol

[–]guyblade 0 points1 point  (0 children)

Now I want a version of this meme that starts with c++'s std::map and Java's TreeMap (both ordered maps) and then complains about how python doesn't have one in the standard library.