4 ms·
I checked out the author: he seems to be an expert, wrote some books. But this article is full of rookie mistakes and I can't figure out the purpose of writing
by SergeAx 6y ago
I checked out the author: he seems to be an expert, wrote some books. But this article is full of rookie mistakes and I can't figure out the purpose of writing it except clickbaiting.
> The main problem with repeating a code chunk is that if a bug is found, there is more than one place where it needs to be fixed.
No, the main problem is that reading repeated code adds cognitive load for reader. Also, when you copy-paste the code you should copy-paste its tests too, and that leads to CI/CD resource wasting.
> The alternative to copy-pasting the code is usually to put it in a function (or procedure, or a subroutine, depending on the language), and call it. This means that when reading through the original caller, it is less clear what the code does.
If the function and local variables all has clear naming and function does not mutate passed variables (which otherwise should be clearly implied by it's name) - you never need to step into it while debugging and just save a bit of time while reading the code.
So, the takeaway here is: the code is written for humans, not computers. The idea of clean code is ease of reading and understanding. That's what DRY is for.