<p>It seems that <a href="https://stackoverflow.com/questions/78019782/how-to-create-an-array-of-similar-object-effectively/78020371#comment137545240_78020088">JS's map and Python's dictionary are equivalent</a>. Is that correct? And if so, why they aren't called the same? Given that JS is newer, why wouldn't the map be called as dictionary as well?</p>

<python><history><terminology><javascript>
What is the difference between JS's map and Python's dictionary?
CC BY-SA 4.0
2024-02-19T13:10:15.217Z
Clarification: These are not the only languages where this happens. Java uses Map and C# uses Dictionary.
kouta-kun
CC BY-SA 4.0
2024-02-19T13:46:42.017Z
A "list" in some languages is the same as a "vector" in other languages. Naming things is hard and agreeing on names is even harder.
mousetail 'he-him'
CC BY-SA 4.0
2024-02-19T18:26:35.033Z
They are the same in some regards and different in others, but it's not clear from your question which differences you would consider significant or insignificant. For example, Python's `dict.get` method accepts a second argument for a default value if the key is absent; and Python's `dict` makes use of `__eq__` and `__hash__` magic methods which have no analogue in Javascript. Python's `dict.values()` returns an itera*ble* while Javascript's `Map.prototype.values()` returns an itera*tor*. And so on.
kaya3
CC BY-SA 4.0
2024-02-20T16:12:16.603Z
Just some of the names used for this data structure in different languages are map, mapping, dictionary, hashmap, hash, table, associative array and array. Most of these names also mean completely different structures in other languages and contexts! Names are hard.
Jasmijn
CC BY-SA 4.0
2024-02-20T21:15:12.937Z
Maps seem to have the most variation in naming. JS map or object, Python dictionary, PHP associative array, Perl hash, Common Lisp hash table.
Barmar
<p>Python dicts and JavaScript Maps are broadly equivalent in role, though the APIs and precise capabilities do differ. The semantics of iteration, key identity, and various additional methods differ, but you can use them for essentially the same tasks modulo that. From the user perspective, it's fair to consider them equivalent, no more different than any two implementations of the same abstract type in different languages might be.</p>
<p>There are programming languages that preceded Python, and both of these names have had significant currency, as do other terms like &quot;associative array&quot;, both before and after. Any of those is a defensible choice of term to use, and in common use there is not a semantic difference between them but simply a choice by the designer, which may be for historic reasons, to avoid overloading a term too much, or simply preference. We see the same range of uses of &quot;list&quot;, &quot;vector&quot;, &quot;array&quot;, and so on, which do sometimes (but not always) have subtle gradations of meaning, but these generally don't exist for the associative structures.</p>
<p>In Python's case, <code>dict</code> is in fact explicitly defined as <a href="https://docs.python.org/3/library/stdtypes.html#typesmapping" rel="nofollow noreferrer">a mapping type</a>, and there is an abstract base class Mapping that it inherits — so we could arguably ask the question in the other direction too. <code>map</code> does also exist in the default namespace as the higher-order function, which would be a conflict, although this <a href="https://www.artima.com/weblogs/viewpost.jsp?thread=98196" rel="nofollow noreferrer">arrived in version 1.0</a> well <em>after</em> the dict type.</p>
<hr />
<p>In the most formal computer-science sense a &quot;dictionary&quot; is actually a form of set rather than an associative structure, although I would <em>almost</em> consider this definition (<a href="https://www.oxfordreference.com/display/10.1093/acref/9780199688975.001.0001/acref-9780199688975-e-1395?rskey=tniiOf&amp;result=1561" rel="nofollow noreferrer">from the <em>Oxford Dictionary of Computer Science</em></a>) obsolete at this point:</p>
<blockquote>
<p><strong>dictionary</strong>: Any data structure representing a set of elements that can support the insertion and deletion of elements as well as a test for membership.</p>
</blockquote>
<p>Associative arrays are dictionaries in this sense (of key-value pairs), but so is the typical &quot;set&quot; abstract data type, and others. &quot;Dictionary&quot; types in programming languages are universally associative structures.</p>
<p>Some consider that &quot;dictionary&quot; implies too much that the keys are strings, although by the same token &quot;map&quot; implies cartography, so I don't think that's a strong reason to favour any particular term. It does appear that possible confusion between this sort of &quot;map&quot; and cartographic maps for JavaScript users <a href="https://archives.ecma-international.org/2011/TC39/tc39-2011-055.pdf" rel="nofollow noreferrer">was considered in 2011</a> when the general Map type was being introduced, but not substantively.</p>
<hr />
<p>In the case of JavaScript in particular, there seems to be a complex but unsatisfying derivation for the use of &quot;Map&quot;:</p>
<ul>
<li>It appears that the &quot;Map&quot; name derives most directly from the preceding &quot;WeakMap&quot; type (a specialist type to allow keys to be garbage collected) that some implementations had had for years, which is an unsatisfying answer.</li>
<li>It's probable that <em>this</em> name in turn derived from Java's WeakHashMap type, given the general trend for JavaScript API design, but discussion logs from the earliest introduction don't seem to be available any more.</li>
<li>Java <em>does</em> have <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Dictionary.html" rel="nofollow noreferrer">a Dictionary type</a> from its very first version, but it was obsoleted by the Map type (an interface rather than a class) very shortly afterwards. All subsequent types have followed the Map pattern.</li>
</ul>
<p>In the end, James Gosling mistakenly making Dictionary a class instead of an interface in 1995 may well be the reason for all of this, though &quot;map&quot; and &quot;mapping&quot; had been used for this already.</p>

CC BY-SA 4.0
2024-02-20T00:45:43.293Z
2024-02-20T00:45:43.293Z
Michael Homer
<p>Background: I was an implementer of Microsoft's JScript engine in the 1990s and for a time a member of the ECMAScript technical committee.</p>
<blockquote>
<p>And if so, why they aren't called the same? Given that JS is newer, why wouldn't the map be called as dictionary as well?</p>
</blockquote>
<p>I see where you're coming from, and yes, every new programming language is implicitly a response to the benefits and shortcomings of previously released languages. But you are over-thinking this a bit.</p>
<p>The notion that in mid-1994 the designers of v1.0 of JavaScript ought to have been choosing names of their methods based on Guido's choices when he released Python 1.0 in January of that same year is charming, but unlikely. JS was not invented to compete with Python, a language for administrative scripting; it was invented to add functionality to web pages. There's no reason Python ought to have particularly been &quot;on the radar&quot; of the design team more than any other early-1990s language, and many reasons why it would be less germane.</p>
<p>Rather: JS was heavily influenced by on the one hand Java, which was perceived as too heavyweight to go in the browser, and on the other hand, Scheme, a very simple, lightweight language but with a syntax perceived as unfriendly to the web developer. Waldemar Horwat much later described the origin to me as something like &quot;JavaScript is Common Lisp with curly braces&quot;, which I think nicely sums up the design problems that they faced.</p>
<p>What we should expect to see, particularly given the very short schedule on which JS was developed, is names of basic concepts and functions would be drawn from three sources:</p>
<ul>
<li>The Scheme / Lisp / etc family of languages</li>
<li>The Java language</li>
<li>Whatever implementation language was used to write the library methods. (A few names in JS are taken straight from the C library.)</li>
</ul>
<p>That's what we should <em>expect</em> to see. What many language designers, myself included, would <em>prefer</em> to see is an approach that takes into account the characteristics of the population of developers most likely to use the language.</p>
<p>Programming languages intended for mathematicians should use the jargon of mathematics; we'd expect &quot;map&quot; in the sense of &quot;function&quot; to be in their vocabulary. A line-of-business programmer, particularly one who came to programming through business rather than academia, is more likely to think of a map as being a plot of terrain used for navigation, so a line-of-business language ought to use a less jargon-laden term such as &quot;lookup&quot; or &quot;dictionary&quot;.</p>
<p>&quot;Dictionary&quot; might be <em>too</em> specific though; we think of dictionaries as being functions from words to definitions, or more generally text to text, but dictionaries are often generalized key-value stores. &quot;Keyed store&quot; though seems to again be jargony. Design is the art of finding good compromises between many design goals. It takes judgment, and opinions will differ from designer to designer.</p>
<p>These considerations weighed heavily upon us when designing features for C#. You'll note for example that the monadic bind operation in C# 3.0 is not called &quot;bind&quot;.  It's called &quot;SelectMany&quot;, because the intended developer audience was not category theorists familiar with monoids in the category of endofunctors, but rather line-of-business programmers manipulating records fetched from databases. It made much more sense to use the language of SQL queries than the language of category theorists.</p>

CC BY-SA 4.0
2024-02-20T04:08:56.980Z
2024-02-20T04:08:56.980Z
Eric Lippert
CC BY-SA 4.0
2024-02-20T18:16:53.310Z
I think it’s worth noting that the user-facing “Map” type didn’t come into being until the ES6 process (entered the spec in 2012), so it’s not 1994-era naming and knowledge that matters.
Michael Homer
CC BY-SA 4.0
2024-02-20T18:30:20.990Z
@MichaelHomer: Great point, thanks for clarifying that. The first edition of the spec simply says that an object is an unordered collection of properties, and that an Array has special behaviours for some named properties. I'd forgotten that detail.
Eric Lippert
# What is the difference between JS's map and Python's dictionary?
Posted by: username_0 on 2024-02-19
It seems that [JS's map and Python's dictionary are equivalent](https://stackoverflow.com/questions/78019782/how-to-create-an-array-of-similar-object-effectively/78020371#comment137545240_78020088). Is that correct? And if so, why they aren't called the same? Given that JS is newer, why wouldn't the map be called as dictionary as well?
**Tags:** python history terminology javascript
> **Comments:**
> **username_1**: Clarification: These are not the only languages where this happens. Java uses Map and C# uses Dictionary.  
> **username_2**: A "list" in some languages is the same as a "vector" in other languages. Naming things is hard and agreeing on names is even harder.  
> **username_3**: They are the same in some regards and different in others, but it's not clear from your question which differences you would consider significant or insignificant. For example, Python's `dict.get` method accepts a second argument for a default value if the key is absent; and Python's `dict` makes use of `__eq__` and `__hash__` magic methods which have no analogue in Javascript. Python's `dict.values()` returns an itera*ble* while Javascript's `Map.prototype.values()` returns an itera*tor*. And so on.  
> **username_4**: Just some of the names used for this data structure in different languages are map, mapping, dictionary, hashmap, hash, table, associative array and array. Most of these names also mean completely different structures in other languages and contexts! Names are hard.  
> **username_5**: Maps seem to have the most variation in naming. JS map or object, Python dictionary, PHP associative array, Perl hash, Common Lisp hash table.  
---
## 2 answers
### Answer by username_7 on 2024-02-20. Score: 5 | Accepted answer
Background: I was an implementer of Microsoft's JScript engine in the 1990s and for a time a member of the ECMAScript technical committee.

> And if so, why they aren't called the same? Given that JS is newer, why wouldn't the map be called as dictionary as well?

I see where you're coming from, and yes, every new programming language is implicitly a response to the benefits and shortcomings of previously released languages. But you are over-thinking this a bit.

The notion that in mid-1994 the designers of v1.0 of JavaScript ought to have been choosing names of their methods based on Guido's choices when he released Python 1.0 in January of that same year is charming, but unlikely. JS was not invented to compete with Python, a language for administrative scripting; it was invented to add functionality to web pages. There's no reason Python ought to have particularly been "on the radar" of the design team more than any other early-1990s language, and many reasons why it would be less germane.

Rather: JS was heavily influenced by on the one hand Java, which was perceived as too heavyweight to go in the browser, and on the other hand, Scheme, a very simple, lightweight language but with a syntax perceived as unfriendly to the web developer. Waldemar Horwat much later described the origin to me as something like "JavaScript is Common Lisp with curly braces", which I think nicely sums up the design problems that they faced.

What we should expect to see, particularly given the very short schedule on which JS was developed, is names of basic concepts and functions would be drawn from three sources:

* The Scheme / Lisp / etc family of languages
* The Java language
* Whatever implementation language was used to write the library methods. (A few names in JS are taken straight from the C library.)

That's what we should *expect* to see. What many language designers, myself included, would *prefer* to see is an approach that takes into account the characteristics of the population of developers most likely to use the language.

Programming languages intended for mathematicians should use the jargon of mathematics; we'd expect "map" in the sense of "function" to be in their vocabulary. A line-of-business programmer, particularly one who came to programming through business rather than academia, is more likely to think of a map as being a plot of terrain used for navigation, so a line-of-business language ought to use a less jargon-laden term such as "lookup" or "dictionary".

"Dictionary" might be *too* specific though; we think of dictionaries as being functions from words to definitions, or more generally text to text, but dictionaries are often generalized key-value stores. "Keyed store" though seems to again be jargony. Design is the art of finding good compromises between many design goals. It takes judgment, and opinions will differ from designer to designer.

These considerations weighed heavily upon us when designing features for C#. You'll note for example that the monadic bind operation in C# 3.0 is not called "bind". It's called "SelectMany", because the intended developer audience was not category theorists familiar with monoids in the category of endofunctors, but rather line-of-business programmers manipulating records fetched from databases. It made much more sense to use the language of SQL queries than the language of category theorists.
> **Comments:**
> **username_6** (2024-02-20): I think it’s worth noting that the user-facing “Map” type didn’t come into being until the ES6 process (entered the spec in 2012), so it’s not 1994-era naming and knowledge that matters.  
> **username_7** (2024-02-20): @MichaelHomer: Great point, thanks for clarifying that. The first edition of the spec simply says that an object is an unordered collection of properties, and that an Array has special behaviours for some named properties. I'd forgotten that detail.  
---
### Answer by username_6 on 2024-02-20. Score: 2
Python dicts and JavaScript Maps are broadly equivalent in role, though the APIs and precise capabilities do differ. The semantics of iteration, key identity, and various additional methods differ, but you can use them for essentially the same tasks modulo that. From the user perspective, it's fair to consider them equivalent, no more different than any two implementations of the same abstract type in different languages might be.

There are programming languages that preceded Python, and both of these names have had significant currency, as do other terms like "associative array", both before and after. Any of those is a defensible choice of term to use, and in common use there is not a semantic difference between them but simply a choice by the designer, which may be for historic reasons, to avoid overloading a term too much, or simply preference. We see the same range of uses of "list", "vector", "array", and so on, which do sometimes (but not always) have subtle gradations of meaning, but these generally don't exist for the associative structures.

In Python's case, `dict` is in fact explicitly defined as [a mapping type](https://docs.python.org/3/library/stdtypes.html#typesmapping), and there is an abstract base class Mapping that it inherits — so we could arguably ask the question in the other direction too. `map` does also exist in the default namespace as the higher-order function, which would be a conflict, although this [arrived in version 1.0](https://www.artima.com/weblogs/viewpost.jsp?thread=98196) well *after* the dict type.

---

In the most formal computer-science sense a "dictionary" is actually a form of set rather than an associative structure, although I would *almost* consider this definition ([from the *Oxford Dictionary of Computer Science*](https://www.oxfordreference.com/display/10.1093/acref/9780199688975.001.0001/acref-9780199688975-e-1395?rskey=tniiOf&result=1561)) obsolete at this point:

> **dictionary**: Any data structure representing a set of elements that can support the insertion and deletion of elements as well as a test for membership.

Associative arrays are dictionaries in this sense (of key-value pairs), but so is the typical "set" abstract data type, and others. "Dictionary" types in programming languages are universally associative structures.

Some consider that "dictionary" implies too much that the keys are strings, although by the same token "map" implies cartography, so I don't think that's a strong reason to favour any particular term. It does appear that possible confusion between this sort of "map" and cartographic maps for JavaScript users [was considered in 2011](https://archives.ecma-international.org/2011/TC39/tc39-2011-055.pdf) when the general Map type was being introduced, but not substantively.

---

In the case of JavaScript in particular, there seems to be a complex but unsatisfying derivation for the use of "Map":

* It appears that the "Map" name derives most directly from the preceding "WeakMap" type (a specialist type to allow keys to be garbage collected) that some implementations had had for years, which is an unsatisfying answer.
* It's probable that *this* name in turn derived from Java's WeakHashMap type, given the general trend for JavaScript API design, but discussion logs from the earliest introduction don't seem to be available any more.
* Java *does* have [a Dictionary type](https://docs.oracle.com/javase/8/docs/api/java/util/Dictionary.html) from its very first version, but it was obsoleted by the Map type (an interface rather than a class) very shortly afterwards. All subsequent types have followed the Map pattern.

In the end, James Gosling mistakenly making Dictionary a class instead of an interface in 1995 may well be the reason for all of this, though "map" and "mapping" had been used for this already.
---
