News for hackers. Stuff that matters.
Re:Don't Be Clever by sjducb on Thursday August 03, 2023 @11:42AM (#36987413)
If you feel confident refactoring some code then you have been able to read and understand it easily. If you can read and understand it easily then it’s good code, leave it alone.
Re:Don't Be Clever by IshKebab on Thursday August 03, 2023 @02:58PM (#36990168)
"Never refactor"? Great advice
Re:Don't Be Clever by sjducb on Thursday August 03, 2023 @05:56PM (#36992562)
That’s not what I said.

If the code is confusing then absolutely refactor it.

There’s 3 levels of understanding DRY

1 programmer is unaware of DRY

2 programmer sees how much simpler code is when you reduce duplication

3 programmer sees how DRY can sometimes cause it’s own problems.

A good clue is that if the cyclomatic complexity of the system goes up when you DRY then you shouldn’t DRY. For example if the new single method is now full of if statements then you’re creating problems.

Another clue is if you’ve just coupled things that shouldn’t be coupled.

Low cyclomatic complexity and coupling of components is much much more important than having a DRY code base.