Goodbye, Clean Code
overreacted.io
Goodbye, Clean Code
1–10 of 599 posts
Re: Goodbye, Clean Code
#2Re: Goodbye, Clean Code
#3Re: Goodbye, Clean Code
#4But I don't think you necessarily need to ask permission to refactor code. On the projects I had the past couple of years everyone understood that code was open to be changed by anyone.
In practice we'd often ask "why did you do X" instead of just rewriting it.
I trusted the people I worked with on those projects though and if they thought they had to rewrite part of my code for whatever reason, that was fine by me. And vice versa, I changed their code and that was fine.
Re: Goodbye, Clean Code
#5what the fuck did i just read
Re: Goodbye, Clean Code
#6what the fuck did i just read
Re: Goodbye, Clean Code
#7what the fuck did i just read
A good post about someone learning that writing code is more than just about how pretty it looks. How you work with others is incredibly important in this industry
Re: Goodbye, Clean Code
#8I agree that not every "smart approach" is worth it if you sacrifice legibility. But I don't think you necessarily need to ask permission to refactor code. On the projects I had the past couple of years everyone understood that code was open to be changed by anyone. In practice we'd often ask "why did you do X" instead of just rewriting it. I trusted the people I worked with on those projects though and if they thoug…
There has to be a very good reason for me to refactor existing/working code for instance for performance.
I won’t refactor code to reduce existing duplication but I will refactor code if I see there is some functionality that I need elsewhere so I won’t just copy and paste.
Re: Goodbye, Clean Code
#9Re: Goodbye, Clean Code
#10There are a lot of situations where 3-5 lines of many methods follow basically the same pattern, and it can be aggravating to look at. “Don’t repeat yourself!” Right?
So you try to extract that boilerplate into a method, and it’s fine until the very next change. Then you need to start passing options and configuration into your helper method... and before long your helper method is extremely difficult to reason about, because it’s actually handling a dozen cases that are superficially similar but full of important differences in the details.
I encourage my devs to follow a rule of thumb: don’t extract repetitive code right away, try and build the feature you’re working on with the duplication in place first. Let the code go through a few evolutions and waves of change. Then one of two things are likely to happen:
(1) you find that the code doesn’t look so repetitive anymore,
or, (2) you hit a bug where you needed to make the same change to the boilerplate in six places and you missed one.
In scenario 1, you can sigh and say “yeah it turned out to be incidental duplication, it’s not bothering me anymore.” In scenario 2, it’s probably time for a careful refactoring to pull out the bits that have proven to be identical (and, importantly, must be identical across all of the instances of the code).