Clean Code guides - GTAC-MGI/GTAC-ESP-LIMS GitHub Wiki
- Use meaningful variable and function names
- Keep functions small
- Don't Repeat Yourself
- Use constants instead of magic numbers
- Use type hints
- Use a functional style / comprehensions - https://stackabuse.com/functional-programming-in-python/
- Use the appropriate data structure for the task - list, dict, set, tuple, namedtuple, set, enum, frozenset, typeddict, class, pydantic data class
- Ravioli code, not spaghetti code - https://dev.to/delia/the-pasta-theory-of-programming-b90
- Avoid side-effects with functions, keep referential transparency in mind (same outputs for every input)
- Code should be self-documenting and intention-revealing - "Code is prose. And design decisions should be narrative."
- Program to an interface, not an implementation (hide implementation details behind a consistant API) https://towardsbettertech.substack.com/p/program-to-an-interface-not-an-implementation
- Use guard clauses https://github.com/Bogdanp/dramatiq/pull/470/commits/3a644c6a5b49a4724907befaadf469ea692b99ea
- Use unpacking - https://stackabuse.com/unpacking-in-python-beyond-parallel-assignment/
- Object-oriented design should follow the SOLID principles - https://youtu.be/pTB30aXS77U?si=-77VJssLnfVUkzn:
- Single-Responsibility Principle
- Open-Closed Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
Helpful links