Framework Design Guidelines

Framework Design Guidelines

There is logic behind the .NET Framework's design. This logic underlies the type names, method names and signatures. In Framework Design Guidelines, Krzysztof Cwalina and Brad Abrams help us understand why things are the way they are. And it shows how we can build similar code.

This page describes and reviews the book Framework Design Guidelines.

Introduction

1

When you first approach the .NET Framework, you will have a lot of questions about why it is the way it is. Why are there methods called Parse, but also TryParse? Why are there certain overloads to methods? But you will also sense some unity in the Framework; it seems to be largely well-crafted and designed that way on purpose. This book explains many of these design decisions.

Tester-doer

Note

As for the question about methods like Parse and TryParse, these are part of the pattern called tester-doer. Mainly, tester-doer is a workaround for the performance problems with exceptions. On page 203, the book describes the Tester-Doer Pattern and Try-Parse Patterns. It tells you when and how to implement these.

Tester-Doer Pattern

Arguments

The book goes into great detail what arguments should be accepted in methods. Also, it tells us how we should reject invalid arguments—methods should check the parameters for null and then throw ArgumentException instances. This is on page 160.

ArgumentException

Methods

Method call

The book gives guidance for naming methods and when to add overloads to methods. For example, on page 227, we see lots of tips for exactly how to overload the ToString method. It states "Do try to keep the string returned from ToString short." The reasoning behind this is that debuggers display this string in the user interface.

Arrays

Question and answer

What about arrays—what types should we use? This book gives some hints about the difference between jagged and multidimensional arrays and when to use them. Jagged arrays, as noted on page 208, often have performance advantages.

Jagged Array Examples Multidimensional Array

Public static readonly fields

Another awesome tip in the book is about public static readonly fields. This approach to adding "const" objects is also found in the C# specification itself. In Framework Design Guidelines, it is found on page 140.

Const Example Public Static Readonly Field The C# Programming Language: Specification

Summary

.NET Framework information

I recommend Framework Design Guidelines for most .NET developers who are focused on improving the quality of their code. It won't change how you think about computer programming, but it will give you insight into the design of the framework. This is important because if you can design code like the code in the .NET Framework, it will be usable for many.

Books About Programming
Dot Net Perls