132
submitted 3 months ago by mao to c/programming@programming.dev

I don't entirely subscribe to the first paragraph – I've never worked at a place so dear to me that spurred me to spend time thinking about its architecture (beyond the usual rants). Other than that, spot on

you are viewing a single comment's thread
view the rest of the comments
[-] nous@programming.dev 4 points 3 months ago

Yup, this is part of what’s lead me to advocate for SRP (the single responsibility principle).

Even that gets overused and abused. My big problem with it is what is a single responsibility. It is poorly defined and leads to people thinking that the smallest possible thing is one responsibility. But when people think like that they create thousands of one to three line functions which just ends up losing the what the program is trying to do. Following logic through deeply nested function calls IMO is just as bad if not worst than having everything in a single function.

There is a nice middle ground where SRP makes sense but like all patterns they never talk about where that line is. Overuse of any pattern, methodology or principle is a bad thing and it is very easy to do if you don't think about what it is trying to achieve and when applying it no longer fits that goal.

Basically, everything in moderation and never lean on a single thing.

[-] Dark_Arc@social.packetloss.gg 1 points 3 months ago* (last edited 3 months ago)

Hmmm... That's true, my rough litmus test is "can you explain what this thing does in fairly precise language without having to add a bunch of qualifiers for different cases?"

If you meet that bar the function is probably fine/doesn't need broken up further.

That said, I don't particularly care how many functions I have to jump through or what their line count is because I can verify "did the function do the thing it says it's supposed to do?" after it's called in a debugger. If it did, then I know my bug isn't there. If it didn't, I know where to look.

Just like with commits, I'd rather have more small commits to feed through git bisect than a few larger commits because it makes identifying where/when a contract/test case/invariant was violated much more straight forward.

this post was submitted on 21 Apr 2024
132 points (95.8% liked)

Programming

16670 readers
141 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS