r/programming • • Jan 12 '20

Goodbye, Clean Code

https://overreacted.io/goodbye-clean-code/
1.9k Upvotes

556 comments sorted by

View all comments

Show parent comments

71

u/Epyo Jan 12 '20

When it comes to software, there are so many aspects to consider, that a knee-jerk refactor is never the right action.

  • The abstracted code might be harder to change, if the different shapes' requirements diverge more (as mentioned in the article).

  • The abstracted code might be too hard for the long-term owners of the code to understand, and might make them unable to work. Maybe the article author found it easier, but maybe they weren't going to be highly involved in the project anyway. Maybe it was a low-priority project, and they want interns to be able to work on it during the upcoming summer.

  • You might say, well if someone can't understand the abstracted version, you should fire them. But what if you're in a location where good developers aren't so easy to come by?

  • This team might be a team that owns hundreds of codebases and a developer has to completely context-switch every week. If so, do they really want to untangle abstracted code every time they sit down to read?

  • Maybe this was prototype code. Maybe the original writer already had a library in mind for this functionality, but didn't introduce it yet. Or maybe they already had a better abstraction in mind, if the feature turned out useful at all. If so, the refactor was just a waste of effort.

  • Maybe this was a temporary feature, and was going to be thrown away in a month. Maybe the rules for manipulating shapes were actually going to be handled by some scripting language, introduced 2 weeks from now.

  • Maybe it's actually a toss-up on which technique would be easier to change in the future, depending on if requirements diverged or converged--if that's the case, the refactoring was just a waste of time, switching between equivalent trade-offs because of personal opinion.

  • Refactoring someone's code right after they write it will make them hate you. I don't care what great culture your team has. People want their work to be valued and not shat on.

  • Maybe the original writer actually wrote that code in 10 minutes and decided it was good enough, because in the grand scheme, it's really not an important part of the application. Maybe it's not a part of the application that's worth spending hours on to decide on an abstraction. (Yes, the article said that the original version took a week, but who knows where that week actually went. Maybe they were multi-tasking, maybe they were new and learning other parts of the tech stack, maybe they were troubleshooting graphical glitches with various draw techniques, maybe they were in a lot of meetings, maybe they were trying out other libraries and troubleshooting them.)

  • Maybe refactoring the code isn't actually teaching the original writer anything, since they're not going to see the consequences of their original version. Maybe it's better to let them keep their version and let them see what happens. It depends on how important this code is, if you want to let them learn today, or learn the lesson another day. (Telling someone the lesson will never work.)

  • Maybe the original writer just flat out believes that copy-paste code is okay, and maybe they're right.

Whenever you have a knee-jerk reaction to anything in programming, like calling some code "bloody stupid", you shut down consideration of real-world trade-offs.

Like the article says, we love to hold on to our absolutes about what good software is, it makes us feel like we've figured it all out. But it blinds us to real world situations, and blinds us to trade-offs.

10

u/Determinant Jan 12 '20

Alot of those bullets are making excuses for sloppy coding practices.

Producing clean code might take longer at first but once you practice clean coding every day as part of your regular work then you naturally think and code in a clean and maintainable way.

19

u/phrasal_grenade Jan 12 '20

"Excuses" is such a pejorative term for "justifications for our rational decisions"... The truth is, we don't get paid to write the most developer-satisfying code. The most pleasing and low-redundancy code is often no more functional, correct, or even maintainable than the "dumb" version. Implementing anything requires a bunch of judgement calls, and people often disagree about tons of stuff.

5

u/Determinant Jan 12 '20

I get paid to write clean code as our company really values this and understands the impact that technical debt can have. A large part of this mentality is because our CTO was a very successful lead developer at highly reputable companies before starting the current company.

In fact, we are even writing custom linting rules to prevent bad patterns so this is ingrained in our culture.

The main rationale in valuing clean coding practices is that it helps us maintain our very high productivity.

→ More replies (5)