- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
he must have used bsearch from pure c with all needed comparators
Admin
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.
Admin
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.
Admin
Yeah, I always like to say "Learn to program, then the language does not matter".
Admin
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?
Admin
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.
Admin
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.Admin
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.
Admin
Python used "dict(ionary)" before C# did, so it's not Microsoft being different. (Where Python got the name from is another question.)
Admin
"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.
Admin
Why should C# be the only place Microsoft chooses to be "the same"?
Admin
TRWTF is Python.
Admin
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 '
Admin
The minus sign combined with quotes in Google search helps a lot for stuff like that. You can weed out the irrelevant results quickly.
Admin
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".
Admin
... 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.
Admin
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)
Admin
Bruce skillfully crafted a hammer.
Using a blacksmith's hammer.
At least everything looked like a nail after that.
Admin
Another WTF is programming languages where it's commonplace to need to search forums to find how the language works.
Admin
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.
Admin
Yeah, that's what I wuz taught too. At a similar date apparently. There were hardware implementations too (aka content addressable memory)
Admin
"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.
Admin
I'm going to go out on a limb here and assume that JavaScript and TypeScript are actually not the same thing.
Admin
"Associative memory" AKA "Content-addressable memory" seems to be used in networking. Apparently each memory cell has its own comparator to input data.
https://en.wikipedia.org/wiki/Content-addressable_memory
I heard that "512k Day" (internet routing failure) was caused by exceeding the capacity of some routers' TCAM chips (a form of CAM).
https://www.noction.com/blog/768k-day-512k-tcam
Admin
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.
Admin
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...
Admin
-1 for people complaining about the name 'Dictionary'. It's just if not more valid than 'Map'
Admin
You got that right. A map represents a spatial system. A dictionary is specifically structured for efficient lookup of keys which aren't locations.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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.
Admin
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".
Admin
Uh, I did. In Mathematics, "map" is actually a synonym of "function".