Names. They should mean something. Argument names shouldn't be
dora, more likelyuser_id_to_instance_dictor something like that.Docstrings. Functions and classes can have documentation strings, you can explain types and structure in them
class UserRegistry: """ Here we tell what does this class do.
class UserRegistry: """ Here we tell what does this class do. Fields: - some_public_field - this field is used to store such and such data Private fields: - _user_id_to_instance - this is dictionary mapping user ID to User instance. """ <class code>Annotations. Python3 allows us to annotate function arguments and output with arbitrary python expression.
def count_women(self, id_to_instance_dict: "dict( user id -> User instance)") -> int:
def average_age(self, id_to_instance_dict: dict) -> float:
def count_women(self, id_to_instance_dict: "dict( user id -> User instance)") -> int: def average_age(self, id_to_instance_dict: dict) -> float:Comments. You can also describe fields with comments: class UserRegistry:
some_field = {} # dict(str -> int) def __init__(self): self.another_field = [] # list(tuple(str, str))
PS. Can someone help me with formatting?