From b76edd9b5e2fd0b64b1adc6c6f2679d5a75d69ec Mon Sep 17 00:00:00 2001 From: ks129 <45097959+ks129@users.noreply.github.com> Date: Fri, 9 Jul 2021 15:12:52 +0300 Subject: Improve wording in The Code Style Guide --- .../events/pages/code-jams/code-style-guide.html | 43 ++++++++++++---------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'pydis_site') diff --git a/pydis_site/templates/events/pages/code-jams/code-style-guide.html b/pydis_site/templates/events/pages/code-jams/code-style-guide.html index fbcb7612..31156da2 100644 --- a/pydis_site/templates/events/pages/code-jams/code-style-guide.html +++ b/pydis_site/templates/events/pages/code-jams/code-style-guide.html @@ -13,7 +13,7 @@ For end-users, the most important parts of the software are functionality and UI/UX. But for developers, there is one more important aspect - code style. While ugly code can do everything that it has to do, developing it further may be a difficult task, - especially if a developer didn't write an original code. + especially if the developer didn't write the original code. Which one of the following do you prefer to read and work with?
MyPath = '/file.txt'
@@ -57,14 +57,15 @@ result = [
The second is definitely easier to read and understand.
- These scripts are small and if you read even first, you can understand what this code does pretty fast,
+ These scripts are small and even with the first code snippet you can understand what the code does pretty quickly,
but what if the project has thousands and thousands of files in a really complex folder structure?
- Do you want then code what looks like the first example?
- You can save hours sometimes if you write beautiful code that follows style rules.
+ Do you want to work with code that looks like the first example?
+ You can save hours sometimes if you write beautiful code that follows the style guidelines.
- The most important document of Python code style is PEP 8.
- This gives the majority of all Python code style rules. This article will cover the most important rules of PEP 8.
+ The most important code style document for Python is PEP 8.
+ This Python Enhancement Proposal lays out the majority of all Python code style guidelines.
+ This article will cover the most important aspects of PEP 8.
Linters
@@ -75,12 +76,12 @@ result = [
Flake8 points out to you rules what you did break in your code so you can fix them.
- Rules
+ Guidelines
Basics
For indentation, you should use 4 spaces. Using tabs is not suggested, but if you do, you can't mix spaces and tabs.
PEP 8 defines a maximum line length of 79 characters, however,
- we are not so strict - we let teams choose a maximum line length between 79 and 119 characters.
+ we are not so strict - teams are welcome to choose a maximum line length between 79 and 119 characters.
2 blank lines should be left before functions and classes. Single blank lines are used to split sections and make logical breaks.
@@ -109,7 +110,7 @@ ListOfMyClass = List[MyClass]
If you have a chain of mathematic operations that you split into multiple lines, - you should put the operator at the beginning of the line and not to the end of the line. + you should put the operator at the beginning of the line and not the end of the line.
# No
result = (
@@ -124,7 +125,7 @@ result = (
+ 2
* 3
)
- If you compare against None
, you should use is
and is not
, but not compare equality.
If you ever check if something is equivalent to None
, you should use is
and is not
instead of the ==
operator.
# No
if variable == None:
print("Variable is None")
@@ -134,7 +135,7 @@ if variable is None:
print("Variable is None")
You should prefer using <item one> is not <item two>
over not <item one> is <item two>
.
- Using second makes it harder to understand the expression.
+ Using the latter makes it harder to understand what the expression is trying to do.
# No
if not variable is None:
@@ -153,13 +154,13 @@ import pathlib, os
# Yes
import os
import pathlib
- Wildcard imports should be avoided in most cases. They make unclear where what comes from.
+Wildcard imports should be avoided in most cases. It clutters the namespace and makes it less clear where functions or classes are coming from.
# No
from pathlib import *
# Yes
from pathlib import Path
- You should use isort imports order specification, what means:
+You should use isort imports order specification, which means:
__future__
imports, standard library imports,
@@ -181,8 +182,12 @@ from pathlib import Path
Comments are really important because they help everyone understand what code does. - But as important as having comments is keeping them up-to-date. - Out-to-date, wrong comments confuse readers. + In general, comments should explain why you are doing something if it's not obvious. + You should aim to write code that makes it obvious what it is doing and you can use the comments to explain why and provide some context. +
++ Keep in mind that just as important as having comments, is making sure they stay up to date. + Out-of-date and incorrect comments confuse readers of your code (including future you).
Comments content should start with a capital letter and be a full sentence(s).
There are three types of comments: block comments, inline comments, and docstrings.
@@ -191,8 +196,8 @@ from pathlib import Path
Probably most common comment type. Should be indented to the same level as the code they describe.
- Each line in the block comment has to start with #
what should be followed by a single space,
- except for text indention inside the comment. To separate paragraphs, use one line containing only #
.
+ Each line in the block comment has to start with #
and should be followed by a single space.
+ To separate paragraphs, use one line containing only #
.
if variable is None or variable == 1:
# If variable is None, something went wrong previously.
@@ -227,13 +232,13 @@ x = x + 1 # Compensate for border
Last, but not least important comment type is docstring, which is a short version of documentation string. Docstring rules haven't been defined by PEP 8, but by PEP 257 instead. - Docstrings should start and end with three quotes (""").
+Docstrings should start and end with three quotes (""").
There are two types of docstrings: one-line docstrings and multiline docstrings.
One-line docstrings have to start and end in the same line, while multiline docstrings start and end in different lines. Multiline docstring has two parts: summary line and a longer description, which are separated by one empty line. - The multiline docstring start and end quotes should be at different lines than the content. + The multiline docstring start and end quotes should be on different lines than the content.
# This is a one-line docstring.
"""This is one line module docstring."""
--
cgit v1.2.3