As I’ve mentioned in passing before now, I’ve started working on the 2nd edition of C# in Depth, to roughly coincide with the release of C# 4 and Visual Studio 2010. So far I’ve just been thinking about what should be added and what should be changed or removed. That’s what I’d like to share today, and I’m really eager for feedback. In particular, I’d like to think of three audiences:
- Developers (possibly hobbyists) who have read one introductory C# book (Head First C#, Microsoft Visual C# 2008 Step by Step or something similar) and are now looking to follow it up. I’m thinking of people with less than a year of full-time development in C#, and not a lot of experience in similar languages. Is C# in Depth too “hard” for this audience? If so, should I try to make it more accessible for them, or is the material inherently too advanced? What might attract such a person to the book in terms of the table of contents?
- Reasonably experienced developers who know C# 2 and 3 already, but haven’t read C# in Depth. They may have heard of it before (I’ve been very pleased in terms of word-of-mouth for the first edition, so thanks to everyone who’s contributed to that!) but not had much real reason to buy another book when they already have something like C# 3.0 in a Nutshell. Now that C# 4 is around, they may be interested in buying something which will explain the new features, and they might as well get a different book rather than just a fresh edition of something they already own.
- Existing readers of C# in Depth. If you already own the first edition, what might persuade you to buy the second edition? How much “new” stuff is required? Would you rather get “more bang for the buck” from a significantly thicker book, or does the relative slimness of C# in Depth hold real appeal? (I know I’m a fan of slim books, but I don’t know quite how important it is. The second edition certainly will be thicker than the first as I’m unlikely to remove much, but I’m sure there’s scope for varying just how much we add.)
Here’s a draft table of contents – only down to headings within a chapter, but with some notes. Changes and notes are highlighted in blue.
Part 1: Preparing for the journey
Chapter 1: The changing face of C# development
- Evolution in action: examples of code change
I won’t be able to include the C# 4 features by just evolving the existing code… at least, not the big ones. Options:
- Stick with the existing example for 1 to 2 and 2 to 3, but change to a different problem for 4
- Try to work out a different example to show all of 1 to 2, 2 to 3 and 3 to 4
- Stick with the existing example, but take it in a different direction for 4, rather than just rewriting the existing code
- A brief history of C# (and related technologies)
Update this with what’s been happening since 2008 and possibly slim down what’s already there
- The .NET platform
Add the new versions, including .NET 3.5 SP1, and introduce the DLR in the terminology part.
- Fully functional code in snippet form
Nothing new to add about Snippy, but there may be another tool to talk about as well.
Chapter 2: Core foundations: building on C# 1
- Type system characteristics
- Value types and reference types
- Beyond C# 1: new features on a solid base
Introduce interface/delegate variance and the
Part 2: Solving the issues of C# 1
Chapter 3: Parameterized typing with generics
- Why generics are necessary
- Simple generics for everyday use
- Beyond the basics
Add a tip and example about using generic static methods in a non-generic type to take advantage of type inference when creating instances of generic types.
- Advanced generics
- Generic collection classes
It would probably make sense to include HashSet<T> here, and possibly any new collection classes in .NET 4.0. Version warnings would be given, of course!
- Limitations of generics in C# and other languages
Refer to part 4 in terms of variance, and possibly trim down the coverage of alternative approaches.
Add an example of Marc Gravell’s work for generic operators, or at least refer to it. Possibly mention the idea of static interfaces. Both give food for thought, but aren’t really part of C#.
Chapter 4: Saying nothing with nullable types
- What do you do when you just don’t have a value?
- System.Nullable<T> and System.Nullable
- C# 2’s syntactic sugar for nullable types
- Novel uses of nullable types
Possibly include Marc Gravell’s teaser about calling all the Object methods on a null value.
Make sure the summary is typeset as 4.5 instead of as part of 4.4. Oops!
Chapter 5: Fast-tracked delegates
- Saying goodbye to awkward delegate syntax
- Method group conversions
- Covariance and contravariance
Mention generic delegate variance in C# 4, referring to part 4.
- Inline delegate actions with anonymous methods
- Capturing variables in anonymous methods
Chapter 6: Implementing iterators the easy way
- C# 1: the pain of handwritten iterators
- C# 2: simple iterators with yield statements
- Iteration in the real world
Renamed section, but keep first example – possibly make it shorter.
Add iteration over lines in a file.
Add generation iterator, referring to LINQ.
- Pseudo-synchronous code with the Concurrency and Coordination Runtime
Fix sample code and explanation, with full article on the web
Chapter 7: Concluding C# 2: the final features
- Partial types
- Static classes
- Separate getter/setter property access
- Namespace aliases
- Pragma directives
- Fixed-size buffers in unsafe code
Part 3: New title TBD
Chapter 8: Cutting fluff with a smart compiler
- Automatically implemented properties
- Implicit typing of local variables
- Simplified initialization
- Implicitly typed arrays
- Anonymous types
Chapter 9: Lambda expressions and expression trees
- Lambda expressions as delegates
- Simple examples using List<T> and events
- Expression trees
Expand for new expression support in .NET 4.0 (clearly labeled as such)
- Changes to type inference and overload resolution
Check if/how this has changed in C# 4.0 spec
Chapter 10: Extension methods
- Life before extension methods
- Extension method syntax
- Extension methods in .NET 3.5
- Usage idea and guidelines
Update advice here and give some more examples.
Chapter 11: Query expressions and LINQ to Objects
Look at changing how the diagrams are formatted in this chapter.
- Introducing LINQ
- Simple beginnings: selecting elements
- Filtering and ordering a sequence
- Let clauses and transparent identifiers
- Groupings and continuations
- New section: extending LINQ to Objects
- Advice for writing your own extension methods
- Plug for MoreLINQ and other libraries
Chapter 12: LINQ beyond collections
- LINQ to SQL
Despite the rumours of its doom, I think this is the best place to start.
- Translations using IQueryable and IQueryProvider
- LINQ to DataSet
- LINQ to XML
- LINQ to Entities
Again, not much depth – still a whirlwind tour.
- Third-party LINQ (renamed from LINQ beyond .NET 3.5)
- Update state of play with third-party providers
- Example of PushLINQ – still using simple delegates, but against different interface
- Remove Parallel Extensions – moved to part 4
Chapter 13: Removed (new chapter at end of part 4)
Part 4: C# 4 (full title TBD)
Chapter 13: Dynamic binding in a static language
- Introduction to the DLR, IronPython, IronRuby
- Calling dynamically – the dynamic keyword
- Reacting dynamically – implementing IDynamicObject
- Applications for dynamic code
Chapter 14: More minor tweaks
- Named and optional arguments
- Variance of interfaces and generic delegates
- Simplifying COM interoperability
Chapter 15: Major new features of .NET 4.0
Even though these don’t affect the language directly, they change the “shape” of code, the way we think about problems. I’m hoping there will be more…
- Bullet-proofing your code with Code Contracts
- Simplifying concurrency with Parallel Extensions
- F# (?)
Chapter 16: Whither now?
- Educated guesses about C# 5
- The Renaissance developer
- Until we meet again
Appendix: LINQ standard query operators
So, how does that sound? What else needs changing from the first edition? Are there any particular sections which would benefit from a neat example? Have I missed anything important that you’d want to see in part 4?
Right now I’ve got a lot of flexibility – so please, I’d much rather hear ideas now than later.