What’s PEP8? And why it’s important?
PEP8 (Python Enhancement Proposal 0008) is a document that makes it easy for developers to get familiar with Python coding conventions.
It describes and explains the bold lines that you should consider when developing your code in Python.
Why it’s important?
Imagine that you’re working in a team with other people, you don’t know each other, you don’t know how each one of you think and take decisions.You’ll have to work on these people’s code, you’ll need to understand the basic layout that these people follow when they want to implement their code.
So, what it’s going to be like when everyone has his own method? Catastrophic codebase, right? Here the PEP8 comes and saves the day for you and your team!
It helps you standardize a set of rules to be followed every time you’re going to change the codebase to implement new features or to review some other existing ones.
WOW, is it unbreakable?
Like many other standards, PEP8 can be easily violated! PEP8 is a great way to come over the conflicts that may happen when you, and your team have no solid standards. But what if it’s the situation when you’re dealing with an existing project with its own standards? It’s recommended that you follow the standards of the project instead. The ultimate goal of standards in the end is the unification of methods people implement their code with.
Ensure quality with Flake8
The flake8 package that helps you checking the code-style and ensuring the quality. It’s maintained by PyCQA, an organization for code quality tools (and plugins) for the Python programming language.
Simple usage of Flake8 with your Python project:
Install the package with your default Python version:
python -m pip install flake8
Be sure to install flake8 with the correct version of Python you aim to use the tool with.
Using the package with your current project
# To check a specific file.
flake8 path/to/code/to/check.py
# or to use it with a whole directory
flake8 path/to/code/
You should see something like this:
Every line contains the line and starting character, and the validation message. Cool, right? You can find more about features and plugins available from the official docs.
Make the most of Flake8 in your development flow
Flake8 can be super useful when it’s injected in your development flow, using the concept of version control hooks. It’s a powerful advantage when you want to make sure that everyone’s code in your team meets the standards. It’s a way of applying the flake8 validation process before any commit is pushed to your original codebase. You can also use this feature to preventing commits that don’t pass the validation process. This one is extremely useful when you’re using some kind of CI (Continuous Integration) processor in your development flow.
Comments
Post a Comment