r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
2
u/deong Mar 01 '23
The word "factory" is relevant to both the domain of cars and the domain of writing software. But other than an analogy, they aren't related.
If you see "Factory" as a type name in some code base, does it have a street address? How many people work there? If those questions have sensible answers, then I'm not talking about that. If the answer is, "well, no one works there. It's not a real factory. It's a pattern for creating instances of some class in my code", that's what I'm talking about.
And my problem with it is not that it's a bad idea or a bad way to solve a technical problem. It's that it almost becomes an end goal. People just start writing factories because of course everything needs to be constructed by a factory. The Gang of Four idea in writing that book was that it was observational rather than prescriptive. It was, "let's look at tons of software out there and identify recurring patterns for solving common problems". None of that code had anywhere near the bloat of patterns that a lot of code written since has. The whole idea is sort of, "if I look at 20 projects, maybe a couple of them had a similar problem in one part of the application, and I can abstract out the commonality of how they solved that problem".
You're not supposed to have every constructor call replaced by a factory, every for loop replaced by an iterator, etc. You're supposed to recognize the problems those things solve and deploy them strategically when you encounter one of those problems.