Code style – or what is Pythonic code?
Pythonic code—when you first hear of it, you might think it is a programming paradigm, similar to object-oriented or functional programming. While some of it could be considered as such, it is actually more of a design philosophy. Python leaves you free to choose to program in an object-oriented, procedural, functional, aspect-oriented or even logic-oriented way. These freedoms make Python a great language to write in, but as always, freedom has the drawback of requiring a lot of discipline to keep the code clean and readable. The PEP8
standard tells us how to format code, but there is more to Pythonic code than syntax alone. That is what the Pythonic philosophy (PEP20
) is all about, code that is:
- Clean
- Simple
- Beautiful
- Explicit
- Readable
Most of these sound like common sense, and I think they should be. There are cases however, where there is not a single obvious way to do it (unless you're Dutch, of course, as you'll read later...