Author: Jon Skeet
Aimed at: Intermediate C# programmer who wants to master the language
Pros: Presents not only the language but also the underlying concepts
Cons: Not for someone looking for a quick guide to the language
Reviewed by: Nikos Vaggalis
I hadn't read a book written by Jon Skeet before but I had been following his articles online and what kept impressing me was his concise writing style; so I was looking forward to get started with C# in Depth 2nd Ed.
Apart from heavyweight names of the .NET world (author Jon Skeet and foreword by Eric Lippert) on the cover, the book is also an eye-catching one. It has an inviting and luxury look as well as utilizing good spacing and readable fonts; little details that can make a big difference and predispose pleasantly before even starting to read.
But is the elegant outside reflected in the content inside?
The answer is definitely yes. It is a combination of a great look with absorbing material.
There is a myriad of books on C# out there and the competition is cut throat
so what makes this book stand out from its competitors?
1.The author does not hide behind technical jargon and uses plain and straightforward language.
2. The author's deep knowledge as well as his communication skills
make difficult to grasp contents easy to absorb.
3. C# programmers of various versions get up to date smoothly.
4. The author's excitement really shines through the book making it lively and animated.
The book does not serve as an introduction to C#, rather it goes through its evolution zooming into its milestones; the important properties that give the language character such as delegates, generics, lambda expressions, extension methods and more.
From C# 1 to C# 4, each versions' newly introduced features are examined, and the already existing ones are compared with their newest counterparts. For example, keeping a close look on the ever changing face of delegates from a type declaration in C# 1 to the lambda expressions in C# 4.
This comparison approach serves as a mediator to understanding the new syntax, or rather the shortcuts or syntactic sugar, but it also has a deeper purpose.
it makes the concepts behind the issues that forced change to occur and drive C# 1 to evolve, much easier to understand.
That is more important than just learning how to use a new feature or learning the new syntax. As the language matures you also mature as a programmer, following C#'s evolution timeline since you get to understand what the problem to address was, semantically, and not just code-wise.
Chapter 1 gives a quick overview of the changes and features added in each version and the differences among versions are visually reinforced with code samples; code snippets long enough to get the point across, not full blown page long code listings which would probably distract rather than aid.
Chapters 2 and 3 go through delegates, generics, the C# type system and value vs. reference types. Delegates are particularly emphasised throughout the language and one could argue that they are difficult to follow, not because the concept is hard to grasp but because the syntax has changed so many times. However, the book provides the most complete walk through of delegates I've ever seen.
The demonstration starts by going through the 'primitive' delegates of C# 1, comparing them to the C# 2 ones, and their story continues to unfold in later chapters.
Smart readers would raise questions which Skeet has the foresight to answer
For example 'why use a delegate and not call the method directly?' Or 'why should I call a method with the same exact signature as the delegate?'. 'What is the difference of an event from a delegate?' Or later on when we meet generics 'why can't I convert a List<string> to a List<object>?
Skeet probably uses his StackOverflow experience where he addresses many kinds of relevant questions and does really explain where others would just scratch the surface.
On the way he debunks some long standing myths such as that 'structs are lightweight classes' Another sample of the didactic approach employed by the author is the use of metaphors ; mapping real world examples to programming concepts such as the metaphor of using the photo copy machine which serves to convey the difference between value and reference types.
Before looking at what you can do with generics, he again reviews the concepts: "first, though we need to understand the problems that cause generics devised in the first place'". Later on when he tackles closures he asks: "what's the point of captured variables?" and when tackling nullable types comments: 'but it's worth looking at the C# 1 options to understand where the problem comes from". These sample quotes sum the essence of the book - taking a deep look at the concepts.
Chapter 4 is on nullable types, and the truth is that I hadn't realised how big a subject that was to deserve a whole chapter devoted to it until I've finished reading it.
Chapter 5: Delegates Revisited, looks at the changes needed to respond to new features, like covariance and contravariance, method group conversions, anonymous methods and closures.
Chapter 6 covers the evolution of iterators and how hard it was to implement them in older versions and Chapter 7 covers miscellaneous features of C# 2 such as partial types, static classes and fixed size buffers.
Then Chapter 8 starts looking at C# 3 , heavily influenced by the introduction of Linq and the innovative features it has brought in, such as automatically implemented properties, anon types and implicitly typed local vars, amongst other. However these features can individually be used outside of Linq and within the C# language itself. For example type inference is extensively used by Linq where a lot of times you cannot use explicitly typing, so you let the compiler decide but it can also simplify non Linq code such as not having to declare a variable's type when instantiating.
Chapter 9 goes through lambda expressions which are not just a syntactic replacement for delegates but serve a deeper purpose: they can be translated into expression trees. What is the big deal? The tree itself is composed of nodes that are objects which represent code. The idea is that representing code as a graph instead of bytecode/IL, permits walking it, manipulating and extending it, as well as semantically transforming it.
Chapter 10 introduces extensions methods and their advantages over inheritance and then Chapters 11 and 12 take a deep look into Linq and why it has revolutionized programming.
After that we get into the C#4 era (Chapter 13) which does not introduce a big bang feature but some minor ones which simplify programming in a few areas. For example, Optional parameters and how one would go simulating them in previous c# versions while their combination with Named arguments renders them a much greater feature.
Chapter 14 introduces dynamic typing into c# which simplifies the interoperation of the language with unmanaged libraries and dynamic languages (through the use of the DLR) and also provides the advantages of the dynamic languages. It goes on to explain what dynamic typing is and what can be simplified by its use. I especially enjoyed the code samples of this chapter, for example sample 14.3 which adds two integers and assigns the result to a string which is a demonstration of weak typing properties (take a look at the section "C# Perl-like behaviour?" of my Strong Typing article) and really adds a twist to the C# typing system.
Chapter 15 explores Code Contracts which might prove an innovative approach to programming mainly for communicating the intentions of the code author more clearly. Then Chapter 16 briefly looks at the future of C# and mainly predicts more injections of functional programming into the language but also warns that careful consideration should be given in the language's design to avoid the danger of the language becoming bloated.
Summing up, I would say that the book does not treat the language as just a tool but as a sophisticated mixture of programming concepts, technological innovations and coding practices. The didactic approach employed and the looking behind the scenes renders this book not a mere presentation of the language and its syntax but as a classroom encapsulated in a book. You do take concrete knowledge away.
As an extra bonus you get access to a private forum where you can contact and question the author directly and you not only get a PDF of the book but also other e-electronic formats such as epub and mobi - a nice touch by the publisher.