Sunday, July 26, 2009

No code has no bugs.

So the more no code you have, the more no bugs you have.

3 comments:

Unknown said...
This comment has been removed by the author.
Unknown said...

Isn't this like saying that 80% of your body heat escapes through your head? Yes, it does once you've covered everything else but that doesn't mean that you can go outside in a snowstorm in just a hat.

Applications require code. Removing all the error checking code won't make the application less buggy.

Fergal Daly said...

Obviously some code needs to stay :)

I recently reported a bug and the fix was in code that looked like

Marvel as blogger makes a pig's mickey out of my code snippet because <pre> tags are not allowed.

def Save(...)
return ValidateDataAndSave(...)

def ValidateData():
if not Conddition1:
MarkInvalid();
return False
if not Conddition2:
MarkInvalid();
return False
if not Conddition3:
###!!!! Missing MarkInvalid()
return False
if not Conddition4:
MarkInvalid();
return False
...
if not Conddition17:
MarkInvalid();
return False

SaveData();
return True


The fix added the missing MarkInvalid. I then submitted a fix to the whole thing to make it look like

def Save(...)
result = ValidateDataAndSave(...)
if result:
SaveData()
else:
MarkInvalid;
return result

def ValidateData():
if not Conddition1:
return False
if not Conddition2:
return False
if not Conddition3:
return False
if not Conddition4:
return False
...
if not Conddition17:
return False

return True

The underlying cause was too much code. What was require was more no code. The first fix only fixed the symptom by adding more code. The only reason the bug could exist was because there was too much code already.