clean-code-systems
Systems
No single person can manage all the details of a city, yet cities work. They have the right levels of abstraction and modularity so that people can work on parts without understanding the whole. Software systems need the same thing. Clean code at the function and class level isn't enough; the system needs separation of concerns too.
1. Separate constructing a system from using it
Startup, which builds and wires objects together, is a different concern from runtime logic. Mixing them is a common mess:
def get_service(self):
if self._service is None:
self._service = MyServiceImpl(...) # lazy init inside business code
return self._service
This hard-codes a dependency on a concrete class and its constructor arguments. It makes testing harder, since you need a fake or real implementation. It also mixes two responsibilities, and when repeated across the codebase it scatters the wiring strategy everywhere. Instead, use one of these: