-
Notifications
You must be signed in to change notification settings - Fork 1
Stylesheet
The style sheet is entirely based on PEP 8, which is a Python conventions document. Furthermore, we are using the Wing Python IDE, which checks the code to make sure that it is following the PEP 8 standards.
1.1.1. Use 4 spaces per indentation level.
Wrong Example:
if (iterator > constant)
do_something()Right Example:
if (iterator > constant)
do_something() 1.1.2. Lines are limited to a maximum of 79 characters
Wrong Example:
total = ((number_of_items * base_price) + (taxes * dollar_quotation) - (sub_total - commercial_discount)) Right Example:
total = ((number_of_items * base_price) + (taxes * dollar_quotation)
- (sub_total - commercial_discount)) 1.1.3. Align operands with delimiter's opening.
Wrong Examples:
# Arguments on first line forbidden when not using vertical alignment.
foo = long_function_name(var_one, var_two,
var_three, var_four)# Further indentation required as indentation is not distinguishable.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)Right Examples:
# Aligned with opening delimiter.
foo = long_function_name(var_one, var_two,
var_three, var_four)
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)1.1.4. Closing brace/bracket/parenthesis may be lined up under the first character of the line that starts the multi-line construct.
Wrong Example:
my_vector = [
1, 2, 3,
4, 5, 6,
7, 8, 9]Right Example:
my_vector = [
1, 2, 3,
4, 5, 6,
7, 8, 9
]1.1.5. A line should break before a binary operator
Wrong Example:
income = (gross_wages +
taxable_interest +
(dividends - qualified_dividends) -
ira_deduction -
student_loan_interest)Right Example:
income = (gross_wages
+ taxable_interest
+ (dividends - qualified_dividends)
- ira_deduction
- student_loan_interest)1.2.1. Surround top-level function and class definitions with two blank lines.
1.2.2. Method definitions inside a class are surrounded by a single blank line.
1.2.3. Blank lines may be used to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners.
Wrong Example:
var_1 = 0
var_2 = 2 ** 5
result = var_1 + var_2
string_1 = “Hello ”
string_2 = “World!”
phrase = string + string2Right Example:
var_1 = 0
var_2 = 2 ** 5
result = var_1 + var_2
string_1 = “Hello ”
string_2 = “World!”
phrase = string + string21.3.1. Imports should be on separate lines
Wrong Example:
import sys, osRight Example:
import os
import sys1.3.2. Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants.
2.1 Comments should be complete sentences.
2.2 All comments must have a blank line above before begins
2.3 Comments must have a maximum of 75 characters per line
2.4 Single line comments must be written with # (space) (comment)
2.5 All comments must be idented with the code
2.6 All comments must begin with first letter capitalized
2.7 All comments must be written in English
Wrong Example:
# Loop to iterate in the range of table
for x in range(0, 3):
#Imprimindo a interação
print(x)Right Example:
# Loop to iterate in the range of table
for x in range(0,3):
# Printing the iterator
print(x)
2.8 Multiple line comments must be writed with """ (space) (comment) (space) """ at the end
2.9 Lines bellow the first one must be allign with the line above
Wrong Example:
# Loop to iterate in the range of table bla bla bla bla bla bla
# Bla bla bla bla bla bla bla
for x in range(0, 3):
#Printing the iterator
print(x)Right Example:
""" Loop to iterate in the range of table
of students """
for x in range(0, 3):
# Printing the iterator iterator iterator iterator
print(x)
3.1 Use '(' in paraghaphs decision structures
Wrong Example:
if age >= 18:
print (maior de idade)Right Example:
if (age >= 18):
print (maior de idade)
3.1 In a Big conditions put space between they
Wrong Example:
if((name=='Carlos'and age==10)or(name=='Ana'and age == 8)):Right Example:
if((name == 'Carlos' and age == 10) or (name == 'Ana' and age == 8)):
3.1 Put white lines between paraghaphs
Wrong Example:
name = input ('digite seu nome')<br />
age = input ('digite sua idade')<br />
people = People(name , age) <br />
print(people.getName()) <br />
print(people.getAge()) <br />Right Example:
name = input ('digite seu nome')<br />
age = input ('digite sua idade') <br />
people = People(name,age) <br />
print(people.getName()) <br />
print(people.getAge()) <br />
4.1 When a structure is subordinated to another, it should be indented under that structure.
Right Example:
if (var_1 > 100):
do_this( )
else:
do_that( )Wrong Example:
if (var_1 > 100):
do_this( )
else:
do_that( )(Wrong because the else instruction is indented under the for instruction, but is not subordinated to it)
4.2 Complicated expressions
In overly complicated instructions you should write each condition in a line, aligned with the condition's open character.
Right Example:
if (((var_1 > var_2) && (var_1 > var_3)) ||
((var_1 > 1) && (var_2 < 10)) ||
(var_3 = 0)):
do_this( )
else:
do_that( )Wrong Example 1:
if (((var_1 > var_2) && (var_1 > var_3)) ||
((var_1 > 1) && (var_2 < 10)) ||
(var_3 = 0)):
do_this( )
else:
do_that( )Wrong Example 2:
if (((var_1 > var_2) && (var_1 > var_3)) || ((var_1 > 1) && (var_2 < 10)) || (var_3 = 0)):
do_this( )
else:
do_that( )
5.1 Use blank lines to separate parts of the routine.
Right example:
def showAccount(accountNumber):
print(accountNumber)
def retrieveAccount(accountNumber):
findNumber()Wrong example:
def showAccount(accountNumber):
print(accountNumber)
def retrieveAccount(accountNumber):
findNumber()
5.1 Use standart identation on the parameters of the routine
Right example:
def setBalance (
id ,
balance,
date,
user
):Wrong example:
def setBalance (id, balance, date, user):
6.1 Avoid characters 'l' (lowercase letter 'L'), 'O' (uppercase letter 'o') or 'I' (uppercase letter 'i') as single character variable names.
6.2 Class names should use the CapitalizedWords convention.
Right example:
class PersonNames:Wrong example:
class person_Names:
6.3 Variable shoud use lower_case_with_underscores convention.
Right example:
person_name = "John"
person_last_name = "Smith"Wrong example:
PersonName = "John"
PersonLastName = "Smith"
6.4 Type variables should use short names following CapitalizedWords convention.
Right example:
AnyStr = Var('AnyStr', bytes, str)Wrong example:
any_str = Var('any_str', bytes, str)
6.5 Exeption names should follow class naming convention with the suffix "Error".
Right example:
except IOError:Wrong example:
except i_o_error:
6.6 Function and method names should be lowercase, with words separated by underscores.
Right example:
def calc_total(number_1, number_2):Wrong example:
def calcTotal(number_1, number_2):