“A long descriptive name is better than a short enigmatic name. A long descriptive name is better than a long descriptive comment.” Robert C. Martin


When writing code we are constantly making changes, adding functionality that we require or just removing the one we don’t need anymore. Learning a programming language and knowing how the algorithms work can be difficult but writing clean code is often even more complicated.
Clean code is a set of principles that seeks code to be:

  • Readable
  • Maintainable
  • Extendable

It is completely important to adopt some good principles when writing code since we usually have the bad habit of naming variables like a or b… What do they mean? You’ll probably remember them while you’re working, but what if you come back in a couple of days, will you remember them?


The philosophy of Python aims to make the code “Pythonic”. One of its developers, Tim Peters wrote the Python Zen which is a set of principles of how we should write code.

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one - and preferably only one - obvious way to do it.
Although that way may not be obvious at first unless you’re Dutch.
Now is better than never.
Although never is often better than right now.
If the implementation is hard to explain, it’s a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea - let’s do more of those!

I like the intention of this Zen and especially the principles:

  • Beautiful is better than ugly
  • Simple is better than complex

We should think simple, if a functionality does not require much effort, then why do we do it? not always something simple is the solution, but if it can be done, do not make it complicated.

PEP8 is a proposal for a style guide for Python code, it is optional, however it makes it easier to write better code, improving readability and quality.

Keep Reading

#dry #python #cleancode #programming #software

Clean Code in Python
3.80 GEEK