How complex should code be?

As Einstein said:

Make everything as simple as possible, but not simpler.

It applies to code as well as to physics.

Use your judgement – will it get easier to maintain? Often by reducing large if/else messes into something smaller you remove corner cases that didn’t need to be there, preventing bugs that may have popped-up in the future. Of course by reducing a clear set of conditions into an obscure twist of boolean logic that only happens to work, you may be making things much more difficult to maintain when something changes.

EDIT:
With the case you cited, if the formula is going to work, then it’s probably the better option – you can even leave a comment citing the source. It’s entirely possible though, that the formula was there before, but was dropped to allow a specific case to be worked around. This is the sort of thing comments in your versioning repository should help with.

Since no one’s posted a link yet, here’s a description of the PID algorithm he’s referring to.

Leave a Comment

tech