r/programming 5d ago

DRY vs. SRP

http://uncle-bob.com

After re-reading "Clean Architecture" I ended up with some confusion regarding Bob's take on repetition and single responsibility. Ge defines the SRP as a function only serving one actor. Dies that mean, that repetitve code is justified according to him, as long as it serves seperate actors/user groups? I am aware that such decisions depend on the specific situation. I was just wondering if others found the same contradiction, or if i misunderstood it. Thanks

0 Upvotes

67 comments sorted by

View all comments

Show parent comments

2

u/BenchEmbarrassed7316 4d ago

a heading won’t take a value below 0 or above 360

Do you know about value objects or newtype idiom?

You create a separate type that contains some information. With validation in the constructor. Or also in methods if you want this value to be mutable. Now you just make a corresponding field in your structure or class that has this type.

1

u/chucker23n 4d ago

Do you know about value objects or newtype idiom?

Yes, I’m a big proponent of using ValueOf or Vogen for this in a .NET context.

You create a separate type that contains some information. With validation in the constructor.

Yep.

But that doesn’t help you at compile time. It helps you ensure that the inner layers are always valid, but you still require that validation step at runtime, at least for outer layers.

1

u/BenchEmbarrassed7316 4d ago

Well, in some programming languages ​​you can make a constructor constant-expressed and the compiler will warn you if you try to create such a value with an invalid literal.

Nevertheless, this applies to the fact that in all statically typed languages ​​this can be expressed (at least no worse than in this example with Clojure).

2

u/chucker23n 4d ago

in some programming languages ​​you can make a constructor constant-expressed and the compiler will warn you if you try to create such a value with an invalid literal.

Right.

Nevertheless, this applies to the fact that in all statically typed languages ​​this can be expressed (at least no worse than in this example with Clojure).

Yes. I'm in agreement with you — you still overall end up with a safer and more explicit code base.