Tim Williams
Jan 21, 2022

--

While I agree with most of your thoughts here, SRP is commonly misclassified. https://en.wikipedia.org/wiki/Single-responsibility_principle#:~:text=The%20single%2Dresponsibility%20principle%20(SRP,it%20should%20encapsulate%20that%20part.&text=Hence%2C%20each%20module%20should%20be%20responsible%20for%20each%20role.

The single responsibility principle is less about duplicate code and more about why the code changes. As Robert C. Martin (the originator of the principle) puts it "This principle is about people." It's more about structuring your code around your organization than it is about code duplication. If two separate functions do the same thing, but the business (logic) verticals they exist within change for different reasons, they are justifiably duplicated.

I've seen well meaning teams try to implement, but misunderstand these principles to the detriment of the overall project. For instance, strict adherence to DRY and SRP can cause overgeneralization, premature optimization and dependency hell.

There's always a balance to strike!

--

--

Tim Williams
Tim Williams

Written by Tim Williams

I am a Web Developer passionate about new technologies, as well as time tested best practices (here’s looking at you Uncle Bob).

No responses yet