Skip to content

Latest commit

 

History

History
146 lines (101 loc) · 2.35 KB

checklist.md

File metadata and controls

146 lines (101 loc) · 2.35 KB

Сheck Your Code Against the Following Points

Code Efficiency

  1. Use the class name to get access to the class attributes:

Good example:

class Person:
    city = "Kyiv"

    def __init__(self, name: str):
        self.name = name
        
    @staticmethod    
    def print_city() -> None:
        print(Person.city)

liz = Person("Liz")
liz.print_city()  # Kyiv

Bad example:

class Person:
    city = "Kyiv"

    def __init__(self, name: str):
        self.name = name
        
    def print_city(self) -> None:
        print(self.city)

liz = Person("Liz")
liz.print_city()  # Kyiv
  1. You can change the bool value in one line:

Good example:

is_married = True

is_married = not is_married

Bad example:

is_married = True

if is_married:
    is_married = False
else:
    is_married = True
  1. Use the static method when needed.

Code Style

  1. Use annotation, it is a good practice:

Good example:

def multiply_by_2(number: int) -> int:
    return number * 2

Bad example:

def multiply_by_2(number):
    return number * 2
  1. Make sure you use the double quotes everywhere.

Good example:

greetings = "Hi, mate!"

Bad example:

greetings = 'Hi, mate!'
  1. Use interpolation instead of concatenation:

Good example:

def print_full_name(name: str, surname: str) -> str:
    return f"{{Name: {name}, surname: {surname}}}"

Bad example:

def print_full_name(name: str, surname: str) -> str:
    return "{" + "Name:" + name + ", surname:" + surname + "}"
  1. Use descriptive and correct variable names:

Good example:

def get_full_name(first_name: str, last_name: str) -> str:
    return f"{first_name} {last_name}"

Bad example:

def get_full_name(x: str, y: str) -> str:
    return f"{x} {y}"
  1. Place each argument on a new line, including self, with proper indentation and formatting

Good example:

def __init__(
        self, 
        name: str,
        age: int
) -> None:

Bad example:

def __init__(self, 
             name: str,age: int) -> None:
  1. It's important to use type annotations for clarity, such as list[Animal] instead of just list to specify a list of Animal instances

Clean Code

  1. There’s no need to add comments if the code is clear and self-explanatory.