Doing work in a property? Back away from the keyboard....

and spend some time reading the Framework Design Guidelines (FDG).

Yesterday, I was perusing a profiling report* trying to pinpoint an obscure performance issue. What I found startled me. A single property getter was consuming a fifth of all CPU cycles. Twenty percent!

The code itself *looked* innocuous. In fact, it was a single line of code performing a straightforward regular expression. The only problem was that this particular property was getting accessed all the time (there were some other design flaws that exacerbated the problem). The real shame is that this particular Boolean property could have been set once in the constructor. Sigh.

Perhaps the Framework Design Guidelines need better iconography. Next to the statement "properties should not be computationally complex" I'd put the icon that signifies "fool me once, no more checkin rights for whomever reviewed your code. Fool me twice, no more checkin rights for you." Suggestions for what that icon looks like are warmly welcomed.

*Props to the Visual Studio 2010 for making performance profiling super easy in 64 bit VMs. This was a huge pain in VS2008. In VS2010, it's as simple as "Analyze -> Profiler -> Attach".

Discuss this post

You're in Easy Mode. If you prefer, you can use XHTML Mode instead.
As a new user, you may notice a few temporary content restrictions. Click here for more info.