Chapter 2. Separation of concerns

This chapter covers

  • Using Python’s features for code organization and separation
  • Choosing how and when to separate code into distinct pieces
  • The levels of granularity in separating code

A cornerstone of clear code is the division of its various behaviors into small, manageable pieces. Clear code requires you to keep less knowledge in your head at any given time, making the code simpler to reason about. Short segments of code with clear intent are a big step in this direction, but bits of code should not be broken up along arbitrary boundaries. Separating them by concern is an effective approach.

Definition

A concern is a distinct behavior or piece of knowledge your software deals with. Concerns can ...

Get Practices of the Python Pro now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.