Time we switched to unicode? (was Explanation of this Python language feature?)

Terry Reedy tjreedy at udel.edu
Tue Mar 25 22:10:23 EDT 2014


On 3/25/2014 9:36 AM, Steven D'Aprano wrote:

> Yes, Python could have changed the meaning of {} to mean the empty set.
> But you know what? The empty set is not that important. Sets are not
> fundamental to Python. Python didn't even have sets until 2.3, and at
> first they were just a standard library module, not even built-in.

Leaving aside the fact that dicts are, conceptually, specialized sets of 
ordered pairs in which first members are both unique to equality and, in 
Python, hashable, this is all true.

> Dicts, on the other hand, are fundamental to Python.  > They are used everywhere.

I would rather say that functions/mappings are fundamental to Python, 
and in programming in general. Dicts are functions implemented as sets. 
Lists and tuples are functions implemented as tables (ordered sets). 
Callables are functions implemented as rules. The fact that functions as 
sets (dicts) are both extremely useful and not built-in to most 
languages, makes their presence in Python a major differentiating feature.

> Python is, in a very real sense, built on dicts, not sets.

It is build on functions, but dicts are a differentiating features. The 
'problem' with sets as sets is that they are purely featureless data 
structures.

 > You can implement sets starting from dicts,
 > but not the other way around:

You should be more careful about claiming impossibility;-).
Sets can be easily implemented from dicts because dicts are sets with an 
extra feature (the value associated with each key) that is easily 
ignored (or always set to the key or None). To implement a dict class 
starting with sets would be difficult because CPython sets and dicts are 
implemented in C and one cannot reach into their C internals from 
Python, or even (mostly) with the C API. One would have to implement or 
even simulate the C structures and code in Python and the result would 
be much slower.

 > dicts are more fundamental than sets.

One can easily implement floats from complex numbers by making the .imag 
part always 0. It would be much harder to implement complex numbers from 
floats, for the same reasons that it would be hard to implements dicts 
from sets. But it must be possible. Would you say that complex numbers 
are, because of this implementation quirk, more fundamental than floats?

> I'm sure it is awfully impressive that mathematicians can derive the laws
> of integer maths starting only from the empty set ∅, but as far as
> programming goes that's not a very useful thing.

I agree. Deriving counts and integers from 0 and an increment function 
is much more apropos to how we use then to describe and drive algorithms 
and prove things about them.

-- 
Terry Jan Reedy





More information about the Python-list mailing list