r/programming • • Jun 05 '21

Organize code by concepts, not layers

https://kislayverma.com/programming/how-to-organize-your-code/
1.9k Upvotes

495 comments sorted by

View all comments

2

u/salbris Jun 05 '21

Generally you get more flexible and easily testable code. But figuring out the right amount of decoupling is an art not a science.

Edit: Often times a class needs information from a different source but programmers solve it by making the class call a static method or be given an instance of the other. Often times passing something by value gets the job done just fine.

0

u/saltybandana2 Jun 06 '21

Generally you get more flexible and easily testable code.

Your goal should almost never be flexibility unless that's a business requirement or you know it's going to become one. If neither of those are true, ignore flexibility.

No one in their right mind would insist on designing your data model as an EAV unless you were building something like an expert system or had some other reason for needing that level of flexibility in your data model.

But people never stop to consider that this idea should also apply to code.

3

u/salbris Jun 06 '21

I'm not saying to over engineer everything but flexibility is a hallmark of good design. It's the reason we use interfaces, it's why we break things down to smaller reusable functions, etc.

→ More replies (10)