Type hints
Type hints are an amazing feature once a codebase grows in size. In early development, not being locked into types and being able to write code more freely allows for faster experimentation. Once a codebase grows it might become confusing which types you can come across. Itβs only when you run into those concrete cases that it starts becoming valuable to add the type hints.
What is the if __name__ == '__main__'
-construct?
It allows you to execute code when the file runs as a script, but not when itβs imported as a module.
Dependency Injection in Python
Dependency Injection is a Design Pattern to achieve loose coupling which simplifies testing. Example from π My Website Generator:
Instead of having a global configuration that can be accessed from anywhere, explicitly pass the configuration to each class or function that needs it.
Without Dependency Injection:
With Dependency Injection:
Resources: