Have you ever come across a poorly written piece of Python code?
I’m talking about a tangled mess where you had to spend hours just trying to understand what piece of code goes where.
Writing code is one part of a developer’s role. Writing beautiful and neat Python code, on the other hand, is a different ball game altogether. This could well make or break your image as a proficient programmer in the analytics or data science space (or even in software development).
So how do we write this so-called beautiful Python code?
PEP 8, sometimes spelled PEP8 or PEP-8, is a document written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan, that provides guidelines and best practices on how to write Python code. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
As Guido van Rossum said, “Code is read much more often than it is written.” You may spend a few minutes, or a whole day, writing a piece of code to process user authentication. Once you’ve written it, you’re never going to write it again. But you’ll definitely have to read it again. That piece of code might remain part of a project you’re working on. Every time you go back to that file, you’ll have to remember what that code does and why you wrote it, so readability matters.
If you’re interested, PEP 8 can be found here.