DEV Community

Discussion on: Clean code, dirty code, human code

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Yeah, honestly, I once got sucked into the clean code rabbit hole, and it nearly ruined my ability to program. I'm not exaggerating. When you become preoccupied with writing clean code obsessively, you redirect your attention from solving the problem at hand.

Nowadays, my process is simple:

  1. Write the code that gets the job done, no matter how ugly it may be, unless a better alternative is reasonably doable without investing more time.

  2. Refactor the code to make it easier to read and/or more performant.

That's it. I think that's all you really need.

Collapse
 
somedood profile image
Basti Ortiz

I hate how it's so simple, yet I still find myself in that "rabbit hole". 🤦‍♂️

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Yeah, I feel ya. And I know exactly how debilitating it can be when you spend hours searching for a "clean" solution to a problem, when you know you're capable of coding up a "dirty" approach in less time.

Thread Thread
 
somedood profile image
Basti Ortiz

More often than I'd like, I'm too pedantic for my own good. It ruins my productivity. I should really work on that.

It puts into perspective why people "iterate" on some code. Initial implementation is expected to be dirty, but that's okay because "iteration" is a thing.

Perhaps that's where my pernicious obsession with "clean code" comes from: I would believe that "iteration" takes up more time than if I had just done it properly the first time. In reality, of course, I end up spending much more time than needed.

Thread Thread
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

I can't quite recall what exactly, if anything, got me into that mindset to begin with, but it happened. Ngl, I'm still kinda dealing with it. There's nothing fundamentally wrong with writing clean code, but I think it's definitely a distraction and should only be a secondary concern, once you have something that at least works. Most of the time, people jump the gun and head straight for the Clean Code promised land.

Collapse
 
lexiebkm profile image
Alexander B.K.

I agree with your approach which involves those two steps. But I do the refactoring if there are enough time to do so. Currently I work alone on both front-end and back-end in a project that has a lot of modules; sometimes there aren't enough time to refactor certain codes in my project.