Best practices for arguments
The signatures of functions and methods are the guardians of code integrity. They drive its usage and build its API. Besides the naming rules that we have seen previously, special care has to be taken for arguments. This can be done through three simple rules:
Build arguments by iterative design
Trust the arguments and your tests
Use
*args
and**kwargs
magic arguments carefully
Building arguments by iterative design
Having a fixed and well-defined list of arguments for each function makes the code more robust. But this can't be done in the first version, so arguments have to be built by iterative design. They should reflect the precise use cases the element was created for, and evolve accordingly.
For instance, when some arguments are appended, they should have default values wherever possible, to avoid any regression:
class Service: # version 1 def _query(self, query, type): print('done') def execute(self, query): self._query(query, 'EXECUTE...