http://docs.python-guide.org/en/latest/writing/structure/#object-oriented-programming
Carefully isolating functions with context and side-effects from functions with logic (called pure functions) allow the following benefits:
In summary, pure functions are more efficient building blocks than classes and objects for some architectures because they have no context or side-effects.
- Pure functions are deterministic: given a fixed input, the output will always be the same.
- Pure functions are much easier to change or replace if they need to be refactored or optimized.
- Pure functions are easier to test with unit-tests: There is less need for complex context setup and data cleaning afterwards.
- Pure functions are easier to manipulate, decorate, and pass around.
This speaks to me especially after trying to test some of my methods in Django and seeing the time and pain costs associated with setting up sufficient context to test them.
No comments:
Post a Comment