Python slang

Steven D'Aprano steve+python at pearwood.info
Sat Aug 6 22:32:23 EDT 2016


On Sun, 7 Aug 2016 04:33 am, Terry Reedy wrote:

> On 8/6/2016 2:30 AM, Michael Selik wrote:
> 
>> When people ask me why the core classes are lowercased,
> 
> Int, float, list, dict, etc were once functions that return objects of
> type 'int', 'float', 'list', 'dict', etc, before they became 'new-style
> classes', which are not just 'classes'.  The lowercasing was maintained
> as new builting classes were added.


That's a good point, but it's not the only reason. After all, come Python 3,
they could have changed their name to Int, Float, List, Dict etc, but
didn't.

These built-ins may be classes, but they continue to be used as if they were
functions, in a context where their function-ness is more important than
their class-ness. (Especially int, float and str.) They were left as
lowercase names even when they could have changed for that reason.

The naming conventions are a little bit inconsistent in Python, partly for
historical reasons, partly for aesthetic reasons. For example, in general
classes which produce "atomic types" tend to be written in lowercase.

By "atomic type", I mean a class which "feels" like it is a primitive,
low-level structure rather than an object with attributes, for example:

- builtins int, float, str, bytes, dict, list, tuple, set, frozenset, bool;
- array from the array module;
- defaultdict and deque from collections;

but not

- Decimal from decimal module;
- Fraction from fractions module;
- Counter and ChainMap from collections module.


although I suppose ChainMap does expose at least the "maps" attribute. But
in my opinion Decimal, Fraction and Counter should all be lowercased, like
float, int and dict.



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.




More information about the Python-list mailing list