DEV Community

Discussion on: What is your advice on writing "clean code" ?

Collapse
peerreynders profile image
peerreynders • Edited on

SRP:

"Gather together those things that change for the same reason, and separate those things that change for different reasons ... a subsystem, module, class, or even a function, should not have more than one reason to change ... separating things that change for different reasons, is one of the keys to creating designs that have an independently deployable component structure."

Responsibilities and "one reason to change" are related but not equivalent.

"Single responsibility" is an oversimplification of cohesion.

Ultimately it's about discovering the boundaries where there is

  • high cohesion within the boundaries but
  • low coupling across the boundaries

something that is easier to recognize than it is to author (and it's the fundamental idea behind Bounded Contexts).

Gather together those things that change for the same reason is a good starting point (to avoid the shotgun surgery and divergent change code smells).

Kevlin Henney rant

Collapse
jeremyf profile image
Jeremy Friesen

The quote of "gather together..." has me realize how very much I love proverbs compared to "rules".