DEV Community

Discussion on: When is code "too clever" / how do you think about readability/cognitive load?

Collapse
 
bgadrian profile image
Adrian B.G. • Edited

Hopefully I don't develop in python, otherwise this would be considered "normal" :))

On a serious note, I usually follow this guidelines, I refactor when:

  • the code would not be understood by a junior, this is a good threshold overall
  • it cannot be tested
  • it will be impossible to find the error source in production (one-liners are the best example, they throw an error in the middle of the line, but there is no way to find out which operation in the pipeline failed)
  • "compiler wannabe optimization" some devs like to pre-optimize and do the same (or worst) than the compiler/runtime already does, sacrificing readability with no real gain
  • when the IDE/linter throws a warning, usually suggesting something better, usually he found an anti-pattern.