• bvs23bkv33 (unregistered)

    he must have used bsearch from pure c with all needed comparators

  • William F (unregistered)

    I am glad Bruce realized his error partway through.

    TRWTF is programmers who have only ever used one programming language. It really limits what you consider possible even in that one language. Each new language teaches a new way to think, new concepts, and new terminology. All of which are extremely valuable when encountering a new domain, problem, or language.

  • (nodebb)

    It's a good thing he fessed up. A dictionary is a book containing words and their meanings or translations. A map is a big piece of paper or a book with pictures of streets and cities from above to aid a traveler in getting from point a to b. Absolutely no need to use a map to implement a dictionary.

  • Karsten Bock (github) in reply to William F

    Yeah, I always like to say "Learn to program, then the language does not matter".

  • (nodebb)

    Pretty sure TRWTF is that this is all stuff standard objects handle. Since objects are, like, everything in JS, it's hard to believe one could miss that.

    Am I missing something?

  • (nodebb)

    The guy spent an afternoon messing around with data structures in his new language. In the process he learned a good way to do his work. He used it, and discarded his mess-around code.

    No WTF to see here. Move along.

  • Stephen Cleary (unregistered)

    There are a few differences between Map and Object. With Maps, keys can be any type. Maps also provide a nicer API over treating objects as dictionaries. It's iterable, keeps track of size, etc.

  • Brian (unregistered)

    TRWTF is C# calling the thing a Dictionary in the first place. "Map" has been a commonly used term for a collection of key-value pairs for decades, but Microsoft decided they just had to be different.

  • Chronomium (unregistered) in reply to Brian

    Python used "dict(ionary)" before C# did, so it's not Microsoft being different. (Where Python got the name from is another question.)

  • Simon Clarkstone (unregistered) in reply to Chronomium

    "Dictionary" is a Forth term, though Forth only has one "dictionary", which is the mapping from names to definitions of every word (identifier) in the current program. Due to its stack-based nature Forth rarely needs local variables, so simple implementations will make all definitions global, having one namespace (the dictionary) for all variable and function definitions.

  • (nodebb) in reply to Brian

    TRWTF is C# calling the thing a Dictionary in the first place. "Map" has been a commonly used term for a collection of key-value pairs for decades, but Microsoft decided they just had to be different.

    Why should C# be the only place Microsoft chooses to be "the same"?

  • (nodebb) in reply to Chronomium

    Python used "dict(ionary)" before C# did, so it's not Microsoft being different. (Where Python got the name from is another question.)

    TRWTF is Python.

  • ooOOooGa (unregistered)

    It always makes me a bit salty when someone gets on my case for not being able to find something on the internet when I don't even know enough about it to search correctly.

    Search engines are great when you know the proper lookup terms - much like a Dictionary/Map. If you have the proper key, finding the data is quick and effective. But search engines are not so good at looking things up by their description.

    I can't count the number of times that I have spent 45 minutes searching around for a solution to some problem or some other piece of information before finally asking a question on a forum or group somewhat related to the topic. Then have the people there say something to the effect of, 'Seriously? You are asking about that? Here: lmgtfy.com/?q=leather+boot+pattern '

    • For the record, years ago when I was originally wanting to make some actual leather boots, all I could find online were crafting recipes for making leather boots in World of Warcraft. Apparently WoW is not so popular any more and I am actually coming up with actual patterns when I use intuitive search terms.
  • Dave (unregistered) in reply to ooOOooGa

    The minus sign combined with quotes in Google search helps a lot for stuff like that. You can weed out the irrelevant results quickly.

  • (nodebb)

    It's really disingenuous to complain about the name that a language gives to this. Even though it's a well known CS concept, the name used within language communities varies widely. Perl calls it "hash", PHP calls it "associative array", Common Lisp has "hash tables". You might not like using the term "hash" in the name, since it implies a particular implementation; but the "as if" rule means that you don't actually have to implement it that way; on the other hand, it also suggests that the implementation performance should be comparable to a hash table (so linear search would be out of the question if the collection is large).

    I don't see anything particularly wrong with the term "dictionary". A real world dictionary is a list of words and their associated meanings. That's as good a metaphor as "map".

  • (nodebb)

    ... or "Table" or "Pair-List" ... there are probably more names for what comes down to idx = find( foo.a == 'x') ; get(foo.b(idx)) than there are computer languages.

  • medievalist (unregistered) in reply to Barry Margolin 0

    But isn't associative array the actual language neutral computer science term?

    That's what I was taught in college (when dinosaurs roamed the earth and FORTRAN was cutting edge)

  • Hephestus (unregistered)

    Bruce skillfully crafted a hammer.

    Using a blacksmith's hammer.

    At least everything looked like a nail after that.

  • Yet Another User Name (unregistered)

    Another WTF is programming languages where it's commonplace to need to search forums to find how the language works.

  • Randal L. Schwartz (google) in reply to Barry Margolin 0

    PHP calls it "Associative Array" because up until Perl version 4, that's what a hash was called. PHP is just a poor badly designed copy of Perl (and as I recall, the first PHP was implemented in Perl), and so a lot of the terminology is very similar.

  • (nodebb) in reply to medievalist

    Yeah, that's what I wuz taught too. At a similar date apparently. There were hardware implementations too (aka content addressable memory)

  • Gumpy_Gus (unregistered) in reply to thosrtanner

    "Associative memory" is one of those pie-in-the-sky computer-science terms that never actually ever seems to get implemented in hardware, at least not at a level a programmer can ever use.

    There are hardware thingies like segment register caches that sometimes are implemented as associative memories but those are a passel of levels unreachable by the average programmer.

  • tbo (unregistered) in reply to kazitor

    I'm going to go out on a limb here and assume that JavaScript and TypeScript are actually not the same thing.

  • (nodebb)

    "Associative memory" AKA "Content-addressable memory" seems to be used in networking. Apparently each memory cell has its own comparator to input data.


    I heard that "512k Day" (internet routing failure) was caused by exceeding the capacity of some routers' TCAM chips (a form of CAM).


  • (nodebb) in reply to jimbo1qaz 0

    CAMs are not commonly available at the software level (in a general sense) simply because they're astonishingly expensive in hardware, both in terms of power and circuit area. By contrast, hash tables are still reasonably fast and can scale up much larger; a CAM with a thousand entries is a really big CAM, but a hash table can grow to many millions of entries with no problem at all. But you do find CAMs powering all sorts of hardware accelerators; for example, the core of an MMU (memory management unit, which implements virtual memory and memory protection in a typical processor) is a CAM.

  • Simon (unregistered) in reply to tbo

    Kind of... TypeScript is one of the many languages that transpiles to Javascript, and is essentially a version of Javascript with stricter compile-time typing...

  • doubting_poster (unregistered)

    -1 for people complaining about the name 'Dictionary'. It's just if not more valid than 'Map'

  • Ulysses (unregistered) in reply to doubting_poster

    You got that right. A map represents a spatial system. A dictionary is specifically structured for efficient lookup of keys which aren't locations.

  • (nodebb) in reply to Chronomium

    C# and python aren't the only languages to call them dictionaries, Java called them that prior to Java 1.2.

    Early C# was designed to attract Java developers, which is likely why Microsoft called them that.

  • Chris (unregistered)

    Maps, in maths terms, are functions which take an input and map it to an output. So calling these associative tables "maps" is perfectly valid. That's exactly what they do. Of course, we see maps as structures rather than functions, but that's more to do with how we use them.

    Dictionaries take an input, and provide the defined output for that. A bit more of a stretch, defining a dictionary like that, but I'll still allow it.

  • Bart (unregistered) in reply to Brian

    The term "dictionary" has also been used for decades in early versions of Visual Basic (in the 90s). It is just as general as "map". I have no doubt the term "dictionary" will be used by various other languages as well. Or even other names might be used. In this specific case of "dictionary" vs. "map", you could take a look at https://en.wikipedia.org/wiki/Associative_array.

    Various things can be named differently in/on various environments/platforms. That will simply never change. So better get used to it, and to the consequences of it as well: if you start using another language/library/platform, you should take your time to get acquainted with its basic terminology and don't assume it's just the same you always have been using up to then.

  • Barf4Eva (unregistered) in reply to William F

    Until it's all irrelevant after a couple decades, so I guess enjoy the relevance while you can... I love writing code, and have worked in multiple languages. But honestly, anymore? Just C# for coding when/if I can. I don't care to put in the time to be an expert in another language, especially considering the time investment. I don't fault others for doing so who truly have the desire. Just not in the stars for me, I'm afraid.

  • Wumpusarama (unregistered) in reply to ooOOooGa

    Knowing what to search for is helpful. I spent weeks creating ..... easing functions for text animations. I wasn't really a Javascript or CSS developer, I was doing desktop video code, and had never heard of "easing functions". There's also apparently this thing called "wheel" which helps objects move, but I made a better version last month.

  • (nodebb)

    I've done stupider.

    In an unfamiliar proprietary scripting language, used for industrial process control, I found the need for a Map, Dictionary, Hash-table, associative array, whatever you want to call it. In short a way to map key to value.

    After much googling, I came to the naive conclusion that no structure existed, and so I nobly embarked on a similar project. Obviously, I wanted it to be reusable so in the interests of "performance" (ironically enough, the largest size this ever grew to was around 100 records), implemented a red-black tree to store the "Key" field. All in all, it was one satisfying day of coding, and about half an hour of debugging when i went to use it (i mean, wrote exhaustive unit tests for it).

    Years later, when working on the code-base of another project implemented in this same language, noticed some esoteric pattern of punctuation which after some simple deductive reasoning I realized implemented a Key-Value store :(

    And before anyone accuses me of not reading the documentation. It was only available in Japanese, and in the form of a scanned PDF, so no easy automated translation in 2003. (OCR was terrible at Japanese back then, and I still believe it is one of the more difficult languages to accurately OCR) .

    I wasn't the worst offender on that project, an electronics engineer who couldn't figure out how to combine Boolean expressions ended up implementing a complex "if" test using a GPIO module with a bunch of open collector outputs and transistor inputs, where his Boolean logic was literally "hard wired" using a bread board of transistors jumper wires and resistors, fed back into an input.

    Addendum 2019-05-23 20:59: Googling... I can't remember whether that was still the era of Alta-Vistering, MetaCrawlering or Dogpiling, or whether Google had actually been invented.

  • (nodebb) in reply to Ulysses

    If looking at the semantics as they apply to the English language, there are many reasons why "Map", "Dictionary", "Hash(table)" are all technically incorrect. The most correct term I've seen is "Associative Array", but it's long and involves two words that most people would have to look up in a Dictionary to learn the meaning of.

  • Gurt (unregistered) in reply to Chris

    In maths, unlike programming, every function takes an input and maps it to an output. You're just describing a function. I have never heard it called a "map".

  • MaxArt (unregistered) in reply to Gurt

    Uh, I did. In Mathematics, "map" is actually a synonym of "function".

Leave a comment on “True Confession: Without a Map”

Log In or post as a guest

Replying to comment #:

« Return to Article