Skip to main content
Fixed code indenting inside list
Source Link
  1. Names. They should mean something. Argument names shouldn't be d or a, more likely user_id_to_instance_dict or something like that.

  2. 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>
    
  3. 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:
    
  4. 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?

  1. Names. They should mean something. Argument names shouldn't be d or a, more likely user_id_to_instance_dict or something like that.

  2. 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.

     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>
    
  3. 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:

  4. 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?

  1. Names. They should mean something. Argument names shouldn't be d or a, more likely user_id_to_instance_dict or something like that.

  2. 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.
    
         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>
    
  3. 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:
    
  4. 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?

Source Link

  1. Names. They should mean something. Argument names shouldn't be d or a, more likely user_id_to_instance_dict or something like that.

  2. 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.

     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>
    
  3. 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:

  4. 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?