Code Convention¶
Table of content
Takeaway¶
-
Use PEP0
-
Always use compiance tools in the headstart
-
Try to consitent, even when you write the violated-PEP008.
-
Focus on the output itself.
-
For Python project, heading with
ruff
orflake8
.ruff
has a performance boot but theflake8
is more concreate. -
Remmember there are
Introduction¶
Code convention is the way we
For Python, the PEP-008 is the headstart is very important
A Foolish Consistency is the Hobgoblin of Little Minds
One of Guido’s key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, “Readability counts”.
A style guide is about consistency. Consistency with this style guide is important. Consistency within a project is more important. Consistency within one module or function is the most important.
However, know when to be inconsistent – sometimes style guide recommendations just aren’t applicable. When in doubt, use your best judgment. Look at other examples and decide what looks best. And don’t hesitate to ask!
In particular: do not break backwards compatibility just to comply with this PEP!
Some other good reasons to ignore a particular guideline:
When applying the guideline would make the code less readable, even for someone who is used to reading code that follows this PEP. To be consistent with surrounding code that also breaks it (maybe for historic reasons) – although this is also an opportunity to clean up someone else’s mess (in true XP style). Because the code in question predates the introduction of the guideline and there is no other reason to be modifying that code. When the code needs to remain compatible with older versions of Python that don’t support the feature recommended by the style guide.
So much learn from the previous. I captured it's whne
I learned alot from PEP008 - which surraound me the pros/cons of each style. When and how to apply to the team
Implement¶
We use ruff
for
We has been used flake8
The pros/con
The backdoor¶
Dont'
Reference¶
https://peps.python.org/pep-0008/