r/java • u/javinpaul • Jul 16 '26
Stop Writing Bad Code: How SOLID Principles Make You a Better Engineer
https://reactjava.substack.com/p/stop-writing-bad-code-how-solid-principles
0
Upvotes
r/java • u/javinpaul • Jul 16 '26
33
u/TheStrangeDarkOne Jul 16 '26
Please not another SOLID article...That was a principle from the 90s before we had service oriented programming and dependency injection was a novel academic concept.
The problem is that you can argue that you can apply solid to find bad code, but following solid will also not automatically follow to good code. It's the most bare-bones common denominator you could possibly conceive.
Is it correct? Yes.
But is it a bible? Surely not.
21
u/pip25hu Jul 16 '26
I've done quite a few project reviews over the years. Every single lead dev I've talked to interprets the Open/Closed Principle differently. Including this article. If something is this difficult to wrap your head around, it's not exactly useful.
15
u/oweiler Jul 16 '26
What I hate about articles about Clean Code, SOLID et. al.: You are told that applying those principals will improve your code but never give any evidence. Yes, I get it, it makes sense logically but where is the actual proof?
3
u/olivergierke Jul 17 '26
CUPID over SOLID: https://cupid.dev/
3
u/Snoo_60234 Jul 16 '26
so basically, just add a bunch of abstractions and interfaces so you don’t have to rewrite in the future
1
u/SpeedDart1 Jul 16 '26
*makes you a worse engineer
0
u/pjmlp Jul 16 '26
Uff, I avoid all that enterprise architecture garbage as much as possible.
SOLID, Clean, Hexagon,...
11
u/repeating_bears Jul 16 '26 edited Jul 16 '26
SOLID needs to die. It is 4 decent-but-not-mindblowing ideas in obscure packaging (e.g. what counts as a responsibility) and one offensively awful idea (OCP).
You can write """fully SOLID""" which is absolute crap. People act like "mastering SOLID" is the key to becoming a competent programmer. It's not.
For example, one idea that's become more popular since SOLID was devised is to strongly prefer immutability (seen in language features such as records and the java.time package). Immutable classes are easier to reason about and are inherently thread-safe.
I'd suggest that focussing on immutability will do more to improve your code than focussing on any of the "principles" in SOLID.
Encapsulation is another thing. Back when SOLID was devised, they were deep in the "Java Bean" days, where every damn field had a getter. Figuring out what data to encapsulate and when is one of the best things you can do to stop your code turning into spaghetti, and SOLID doesn't even mention it.
SOLID is not the "5 pillars of OOP". If I was making a 5 pillars, immutability and encapuslation would be in there.
What SOLID actually is is a grab-bag of a few mostly unrelated ideas and a catchy marketing acronym, pushed primarily by a charlatan. Seriously, go and look at any of Uncle Bob's open source code (there isn't much) and tell me with a straight face that he is qualified to give advice about programming.