I read through Jeffrey Richter’s CLR via C# not too long ago. This evening I cracked it open again and jotted down a few notes on what I personally took away from the book. Of course, if I spent the time to write down everything I learned, I might still be busy writing. I’ve thrown in the towel and though I’m probably not doing the book justice, here are 15 random things I have learned from Jeffrey Richter:
Page 3 – Way more than I ever wanted to know about the CLR’s execution model. That is, everything about Managed Modules, Assemblies, Intermediate Language (IL), Framework Class Library (FCL), Common Type System (CTS) and Common Language Specification (CLS.)
Page 56 – How to properly version your assemblies – including a breakdown of the assembly version resource information, how/when to increment the major, minor, build and revision numbers, and the distinction between AssemblyFileVersion, AssemblyInfomationVersion and AssemblyVersion numbers.
Page 144 – Best practices on how to write code to compare objects. Here, Richter drills into object equality, identity and hash codes.
Page 177 – How the compiler handles constants – their values are embedded inside the IL code at compile time.
Page 185 – Why one must beware of code explosion with initializing fields within classes with multiple constructors. Key points: Any fields that the constructor doesn’t explicitly overwrite are guaranteed to have a value of 0 or null. The compiler embeds, at the beginning of all constructor methods, field initialization code. You should consider not initializing the default field value at the point of field declaration and instead perform the common initialization in a single constructor and have all other constructors explicitly call the common initialization constructor before overriding varying defaults.
internal sealed class SomeType
// Do not explicitly initialize the fields here
private Int32 x;
private String y;
private Double z;
// Sets all fields to their default
// All constructors explicitly invoke this constructor
x = 5;
y = "Ben";
z = 3.14159;
// Sets all fields to their default, then changes x
public SomeType(Int32 x) : this()
this.x = x;
// Sets all fields to their default, then changes y
public SomeType(String y) : this()
this.y = y;
// Sets all fields to their default, then changes x, y
public SomeType(Int32 x, String y) : this()
this.x = x;
this.y = y;
Page 254 – The power of string interning and string pooling.
Page 309 – How to perform unsafe array access and fixed-sized arrays.
Page 322 – How to implement multiple interfaces that have the same method name and signature and…
Page 325 – Why you need to be really careful when using explicit interface method implementations.
Page 365 – A quick introduction into Wintellect’s Power Collections library which extends the .NET Framework’s Class Library with an assortment of collection classes. The Power Collections library, documentation, and licensing information is available on CodePlex.
Page 411 – How the CLR provides special support for Nullable value types.
Page 431 – A little background on System.Exception, System.SystemException and System.ApplicationException and how Microsoft through the basic principles out the window.
Page 457 – Way more information than any single person should know about Garbage Collection (GC).
Page 562 – How to build a system which support add-ins.
Though it wasn’t mentioned in the book, Richter’s Power Threading library (DLL) contains many classes to help with threading and asynchronous programming for the .NET Framework, Silverlight, and the .NET Compact Framework. Jeffrey has described many of the classes contained in the library by way of his MSDN Magazine Concurrent Affairs columns and I found his Channel 9 overview on the AsyncEnumerator class (which uses Yield to simplify multithreading) absolutely fascinating. The Power Threading Library is available for download here.
That’s fifteen. I should probably drill into a couple of these with code samples…or you could just get a copy of the book.
Random closing thought: When I was flipping through the book today I found a spider smashed between pages 72 and 73. Ironic?