Is there any significance to the capitalization practices for classes in the collections
module in Python? In particular, I find it puzzling that OrderedDict
uses CamelCase while defaultdict
is all lowercase. My assumption would be they would all use CamelCase since they are all classes.
First, Python is a programming language with a defined syntax and specification. When referring to the language, we will capitalize the name as "Python".
Package and Module Names Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
You'll see camelCase in some really old Python code but it's not the modern convention at all. Write your code according to the conventions so other Python developers will know what kind of construct they're dealing with when reading your code.
The naming is historical (for CPython). Originally, CamelCase classes (like OrderedDict
) were pure python implemented and other classes (like defaultdict
) were C-implemented. However, now the names are just legacy (mostly), since C-implementation has often been added (e.g. here for OrderedDict
- you can see now that the python implementation is only a fallback).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With