Monday, September 12, 2005

PDC Precon Monday: Framework Design Guidelines



Update: Slides are available here.

Today I'm attending Brad Abrams and Krzysztof Cwalina's talk on "Framework Design Guidelines". I got a copy of their new book just for attending -- cool! Of course, we were all affected by the power outage in LA which delayed things for a bit. I think it was all the flat screens, projectors, computers and geeky gadgets here at the PDC that caused the problem...

I spend a lot of time reading Brad and Krzysztof's blogs so it's really neat seeing them in person.

Anyhow, they are essentially going over much of what their new book is about, how to design a great public API that is in the same style and has the same best practices as the .Net Framework itself. Lots of great learnings.

To give you a sample: when you are defining EventHandlers, its best to create your own delegate and have a subclass of EventArgs as your second parameter... even if you don't have anything specific to put in it now. Why? Because if you ever need to pass arguments to your listeners of that event (by changing the delegate definition), you'll have to break the API for all listeners.

Generics makes the definition of the EventHandler much nicer now that they have a generic EventHandler type that takes two types, one for the sender and one for the EventArgs.

Something like:
public event EventHandler MouseMove;

Another big savings in JIT compiled code (see my article here).

Of course, the funny thing is that a ton of the APIs in the .Net Framework don't follow this guideline. This is one of the guidelines which Microsoft themselves figured out when trying to make non breaking changes to the framework.

That said, with regards to guidelines, for me, the biggest problem I face in this area is not about knowing what these guidelines are but how to actually lead a team in creating a code base that follows the design guidelines and best practices.

Some of the things I have found to be difficult are:

1) Getting aligned around the importance of code conventions, design guidelines and best practices.

2) Ensuring that everyone is diligent to learn the code convention, design guidelines and best practices for the project. Not just learn but internalize.

3) Dealing with situations where interim developers come and go on the project and need to accomplish something in the code base in a hurry and can't take the time to ramp up. This is one of the many problems associated with balancing the short and long term goals of a code base.

4) Finding the resources to refactor code that is written to address short term goals

I find that having code reviews (including running FxCop as a part of the nightly build) and trying to work closely with the developers goes a long way but doesn't completely solve the problem.

It's a hard problem -- I wish they had a session on how to solve that! :)

Anyhow, the format of the session today is pretty good. They are taking turns and going over various concepts and doing code review exercises at the end of each section.

Bill Gates and Jim Allchin are the keynote speakers tomorrow, I'm going to try to get there early enough to get a good seat. Jim is going to discuss how to take advantage of Windows Vista in your application -- should be good.

0 Comments:

Post a Comment

<< Home