View on GitHub

Ann Molly Paul

learn -- code -- inspire

Three pointers in writing reusable python code

April 9, 2015

More Functions better than classes.

Functions that share the same state can live in a class.
Smell an Anti-pattern: When there's only one public function in a class, the class can be removed and the function can be a global function.

Functions ARE NOT Procedures

Rule of thumb: Function should should either return computed stuff or have a side-effect by mutating what it was passed
Smell an Anti-pattern: Replace chars and return no of chars replaced

Don’t try solve everything

All edge cases/ all future cases
Base function on use-case agreed to solve
Testing smaller modules(functions) is much easy. So test, test, test!