HomeEducationDRY vs SoC, a tough alternative | Swizec Teller Acquire US

DRY vs SoC, a tough alternative | Swizec Teller Acquire US

My favourite supervisor known as this “essentially the most vital idea for a software program engineer to know”. How do you select between DRY – don’t repeat your self – and Separation of Considerations?

DRY vs SoC, a tough alternative

That is enjoyable as a result of Do Not Repeat Your self and Separation of Considerations are engineering maxims that all of us parrot as important guidelines of how software program is constructed. However once they butt heads we get caught as a result of we perceive the phrases, not the concept.

DRY is the primary rule each software program engineer learns. My highschool C professor beloved to share this instance from a parent-teacher convention. (sure I went to a bizarre college)

She as soon as wrote an examination that stated “Print numbers 1 to five”

The coed solved it like this:






And acquired an F. The dad and mom complained. “Does this code not do what the query requested?”

Think about the professor rubbing her temples in frustration. “Ugh sure, however it’s flawed … what if N was 100? Are you gonna add 100 extra traces?”

“Yeah, that sounds straightforward. Would it not not work?”

She was on the lookout for one thing like this:

for (int i = 0; i < 5; i++)

printf("%dn", i)

You DRY up the print, make it take an integer parameter, and run the entire thing in a loop. Now there’s just one place to make a mistake change once you wish to replace the output.

Separation of Considerations is DRY’s reverse cousin. It talks about detangling code so it will possibly work in isolation.

Engineers be taught this one by getting hit within the face with a shovel they left mendacity round. Unit testing and TDD are widespread tips to encourage this apply. Cannot take a look at issues in isolation if they are not remoted.

The best inform that you might want to separate issues is when the phrase “and” sneaks into your description of a category, perform, or element.

Think about if sending an electronic mail additionally wiped your onerous drive. You most likely need completely different buttons for that …

DRY and SoC are guidelines, ask anybody. This is the nuance folks miss: They don’t seem to be speaking about code.

These are conceptual guidelines. You need to DRY ideas, not code. Identical with separating conceptual issues. Sending electronic mail and wiping drives must be separated, however “flip off lights and music” is a wonderfully smart operation to carry out once you go away the home.

This is an instance we’re coping with at work.

You might have two database tables, they appear to be this:

Two similar tables

Two related tables

Two tables, completely different names, identical columns, each with a many-to-many relation to appointment sorts. Do you have to DRY them up?


That is the issue we’re coping with. Years of this being DRY as a result of it appears to be like related and now it is a ache to detangle.

“Service Line” and “Care Kind” are completely different ideas. Regardless of superficial similarities. Service traces are a advertising and marketing idea that drives how appointments seem to customers. Care sorts are a scientific idea that drives which suppliers can do what.

Neglect if the code appears to be like related. Is it describing the identical enterprise idea? If sure, DRY. If no, separate.


Printed on April eleventh, 2023 in Classes, software program engineering,

Senior Mindset E book

Get promoted, earn a much bigger wage, work for prime corporations

Be taught extra

Have a burning query that you simply suppose I can reply? Hit me up on twitter and I will do my finest.

Who am I and who do I assist? I am Swizec Teller and I flip coders into engineers with “Uncooked and trustworthy from the guts!” writing. No bullshit. Actual insights into the profession and abilities of a contemporary software program engineer.

Need to grow to be a true senior engineer? Take possession, have autonomy, and be a power multiplier in your crew. The Senior Engineer Mindset book may also help These are the shifts in mindset that unlocked my profession.

Interested in Serverless and the trendy backend? Take a look at Serverless Handbook, for frontend engineers

Need to Cease copy pasting D3 examples and create knowledge visualizations of your individual? Learn to construct scalable dataviz React elements your entire crew can perceive
with React for Data Visualization

Need to get my finest emails on JavaScript, React, Serverless, Fullstack Internet, or Indie Hacking? Take a look at

Did somebody superb share this letter with you? Fantastic! You may join my weekly letters for software program engineers on their path to greatness, right here:

Need to brush up in your fashionable JavaScript syntax? Take a look at my interactive cheatsheet:

By the best way, simply in case nobody has informed you it but at the moment: I really like and admire you for who you’re

#DRY #SoC #tough #alternative #Swizec #Teller

Continue to the category


Please enter your comment!
Please enter your name here

- Advertisment -spot_img

Most Popular

Recent Comments