Monday, June 13, 2011

Not calling your base class in your override ought to be a warning.

I just spent twenty minutes chasing a weird behavior in a RadRibbonForm that turned out to be caused by the fact that my form's Shown event was never called.  It took a while to figure out that I had commented out a large section of my OnLoad override - too large, in fact.  In disabling some code I accidentally also commented out the first line:
base.OnLoad(e)

There are really very few times when you don't want to call the base class implementation, particularly of more complex classes.  Those times when you truly don't, the member is usually pure virtual anyway.  For those times that you really don't want to call the base class, just like those times when you really DO want to fall through a case statement, there ought to be some indication from the programmer that "Yes, I really do know what I'm doing, and this wasn't a mistake".

It would have saved me 20 minutes, anyway.

No comments:

Post a Comment