Thursday, January 16, 2020

Focusing on code readability/quality in Python

I've been writing code in Python for almost over a decade now (7 years in Academia, 3+ years in Industry). I've also read a ton of Python code written by others. Python programmers who come from Java may be influenced by the Java-style of programming (variable names, comments style, etc.). The same stands for C/C++ programmers, PHP, SWIFT, etc. who code in Python.

The style of programming in Python greatly influences the readability of code one writes. Since Python lays more emphasis on readability, it is important to properly vet your code (especially when you want the code to be contributed to a large project).

For passionate Python programmers, I don't have to remind them of PEP20 (Zen of Python) and PEP8 standards. These provide important guidelines on how to write code in python with a focus on simplicity and readability.

To properly incorporate these standards into your writing style, one could use linting (for static code checking). I use PyCodeStyle frequently. Pylint is another program that one could use for linting which rates your code (out of 10). One can configure these linting tools to follow standard python coding style practices into your code.

One could configure them to run on your code within the IDE/editor (like VSCode/PyCharm).