how to reduce bugs due to incorrect indentation

msustik at gmail.com msustik at gmail.com
Wed Feb 5 22:02:09 EST 2014


I had a bug in a Python script recently. The code in question was something along the lines of:

if a == 1:
    x = y
else:
    x = z
y = z + y
z = z + 1

While editing this file I accidentally pushed TAB on the line with 'y = z + y'.

My changes were elsewhere and I did not notice the above one line change when I looked at the diffs before commit. I should have noticed it...

It was rare that a was 1 and therefore the problem did not show up for a while. (I know I should have had tests exercising all cases...)

When the bug showed up, it was kind of difficult to remember what was the original intent. Fortunately, looking at old versions allowed me to find the problem commit and the bug.

Any suggestion on how to avoid this type of error in the future?

Thanks!



More information about the Python-list mailing list