Monday, May 20, 2013

easy way to maintain source code decorum


It's best to maintain source code in a clean, pretty state. It's easy to read, and more importantly easy to find small code changes that might lead to dramatic effects.
But, during development, people add debugging statements. Print statements, debug logging, and things like "# XXX fix this".  Letting this code hit production is not good, as it confuses the normal operation of the system.

To pick bits of debugging fluff from your code, add this to your top-level Makefile.  Before merging your code with the main branch, run "make sniff" to sniff your code for unwantedly smelly bits, like leftover debugging code.

The following will only check newly-changed code, and won't warn on old smelly code:

sniff:
git diff develop | awk '/(debug|XXX)/ { print $$1; found=1; } END { exit found }'

If this is run as part of a Jenkins job it'll flag stinky code as an error. 

No comments:

Post a Comment