Effective C#: 50 Specific Ways To Improve Your C# by Bill Wagner
This is one of those books that lists 50 different issues and pieces of advice for using the programming language – there are variants for C# and Java and many other languages. The items are divied into 6 different chapters.
Chapter one, “Language Idioms” discusses some language level issues – avoiding user defined conversion operators, conditional attributes instead of #if and using “is” and “as” instead of casting. All of the advice seems very reasonnable. The next chapter is on “Resource Management”, and goes into detail about class initialization and then covers the standard Dispose pattern. Immutability and when to use a value type instead of a reference type are also covered.
Chapter three, “Expressing Designs in C#” is very good and full of lots of good advice. Limiting visiblity and not returning references to internal objects are covered, as are using interfaces instead of inheritance and the difference between interface methods and virtual methods. There are items on defining callbacks using delegates and using the event pattern for notifications. In this mixed bag, there is a discussion about making chunky rather than chatty calls, and also a discussion of co- and contra-variance.
Chapter four is entitled “Working With The Framework”. This covers ordering relationshps with IComparer<T> and IComparable<T> and then moves onto writing parallel algorithms using PLINQ.
Chapter five covers the dynamic type, in a chapter with the rather misleading title of “Dynamic Programming in C#”. There’s a lot of discussion about how dynamic works, and a good explanation of expression trees.
The last chapter, “Miscellaneous”, throws in some advice about boxing and structuring applications as sets of small assemblies.
There were some items that I found very useful. How to use IFormattable to define better string representations for types, minimizing duplicated constructor logic and some of the PLINQ notes in particular. Not a bad book, but some of the advice is either well known or potentially just a matter of opinion.