Python中内置了强大的函数式编程,特别是lambda表达式,使得代码更加简洁美观。
以下几条则是从《Learning Python》中摘抄的 Function Design Principles
- Coupling: use arguments for inputs and return for outputs.
- Coupling: use global variables only when truly necessary.
- Coupling: don't change mutable arguments unless the caller expects it.
- Cohesion: each function should have a single, unified purpose.
- Size: each function should be relatively small. (Keep it simple, and keep it short)
- Coupling: avoid changing variables in another module file directly