Code style – What is Pythonic code?
When you first hear of Pythonic code, you might think it is a programming paradigm, similar to object-oriented or functional programming. 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 they have the drawback of requiring more discipline to keep code clean and readable. PEP 8 tells us how to format code and PEP 20 is about style and how to write Pythonic code. PEP 20, the Pythonic philosophy, is 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 write your code (unless you’re Dutch, of course, as you’ll read later in this chapter). That is the goal...