Functions & Classes#
The primary tool for reusable code: the function.
Modularity: break problems into small pieces
Abstraction: hide the “how,” expose the “what”
Testability: verify functions in isolation
Collaboration: team members build different functions
Descriptive verb-noun name (
calculate_mean, notdo_math)Single responsibility: one function, one job
No global variables: pass everything as arguments
More advanced codebases can benefit greatly from a more versatile structural coding pattern: the class.
Encapsulation: bundle data and behavior
State management: retain data across operations
Inheritance: extend and reuse existing structures
Descriptive noun name (PascalCase, e.g.,
DataProcessor)High cohesion: methods tightly related to class data
Low coupling: minimized dependencies on external components