#hack trick: a quick dirty way to avoid human error whilst debugging

When I'm debugging, and in a rush, I can be sloppy. It's human nature! It really annoys me though when I forget to clean up my hacks after I've quashed a bug.

Here's a simple trick I've started using in PyCharm, when debugging Python. I label my hacks with #hack which PyCharm nicely lights up in bold red for me:

What really helps though is that when I try to Commit without removing the hack, PyCharm warns me! (be it in a slightly cryptic way, via a TODO item warning). Git hooks would be a better alternative here (perhaps based on this), but if you've a windows machine, this can be a pain!

Here's how to do this yourself. Select 'Configure' in the above window (making sure that 'Check TODO' is selected). Then select 'Edit Filters'.

 

Create a new Filter, by selecting the + icon. I've used the settings below.

 

I asked people on Reddit and a facebook Django group about how they avoid this human error (leaving in debugging efforts accidentally) and I got some stick about not knowing how to unit test properly. But does anyone honestly write unit tests to check that ALL their debugging hacks are removed after? Surely not. KISS rules in my opinion. We are all human after all.

This article was updated on 26 June 2018

Comments