RFC: C# in Depth 2nd edition, proposed changes and additions

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.
  • Summary

Chapter 2: Core foundations: building on C# 1

  • Delegates
  • Type system characteristics
  • Value types and reference types
  • Beyond C# 1: new features on a solid base
    Introduce interface/delegate variance and the dynamic type.
  • Summary

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#.
  • Summary

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.
  • Summary
    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
  • Summary

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
  • Summary

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
  • Summary

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
  • Summary

 


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.
  • Summary

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
  • Joins
  • Groupings and continuations
  • New section: extending LINQ to Objects
    • Advice for writing your own extension methods
    • Plug for MoreLINQ and other libraries
  • Summary

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
  • Summary

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
  • Summary

Chapter 14: More minor tweaks

  • Named and optional arguments
  • Variance of interfaces and generic delegates
  • Simplifying COM interoperability
  • Summary

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# (?)
  • Summary

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.


 

42 thoughts on “RFC: C# in Depth 2nd edition, proposed changes and additions”

  1. “Introduce interface/delegate variance”

    Because the two are joined, I think you need to qualify this as “generic type variance”. Delegates are already parameter type co- and contra-variant.

  2. sounds good to me (I have partially read the book). I definitely would by this new edition to get a quick yet in-depth introduction into the new features

  3. I love how involved in the development community you are. But alas, I have no suggestions for the new edition as I haven’t read the earlier edition (yet).

  4. I think I would add a 4th target audience.

    Developers who are targetting the latest framework, but haven’t evolved their programming to take advantage of the latest features. Even experienced developers will have jumped to c#2/3 without being able to take the time to learn the new features adequately enough to take advantage.

    These sort of developers don’t want to buy one of the revised standard text books as they already know much of the material (and the revised edition likely has everything mixed in). I think this is were c# in depth has been very helpful. It fast tracks you to the latest c# without having a massive textbook, and without starting out as if you’re a beginner.

    I think the orginal book was accessible enough for all but the earliest beginner.

    More feedback later…

  5. Yay, a new edition of “C# in Depth”! I have the current one and will definitely buy the next one since I’ll be eventually using C# 4 anyway. Just adding coverage for the new C# 4 features is fine with me.

    As for making the book more accessible to newbies, I don’t think that’s worthwhile unless you also include a description and tutorial for the entire C# language. Your post doesn’t sound like you’re about to do that, though, and since readers will still need to have learned about C# basics elsewhere it’s okay to keep the discussion at a higher level IMO:

  6. Sounds like you’ll be busy…

    Re generic operators: note that `dynamic` also provides this (although not in the CTP) – I’m waiting for the beta with my “run” key ready, to see how fast it is…

    Re part 4 – I almost wonder whether it is “gentler” to swap 13/14 – get the easy bits out the way, *then* hit ‘em with the DLR.

    Re 1 – “The .NET platform”; in the Figure 1.5, is Silverlight in the wrong column? Additional candidates (in addition to “core” product): Mono 2.x, Silverlight 2.x, ASP.NET MVC

  7. Looks very promising
    Will definitely buy

    I know it’s not part of the C# language itself but wouldn’t it be cool to have a few words on the ‘compiler as a service’ feature?

  8. Please please please resist the urge to fatten the book out with newbie stuff. I think the book’s biggest selling points are it’s conciseness and the level to which it’s pitched.

    It’s far easier to pay attention to book that has avoided filler. You only need one or two pages of 101 to break your concentration.

    The only other book I have that does this really well is Fowler’s UML Distilled.

    There are plenty of books out there that cater for beginners. If you want to tap this market, perhaps consider an even smaller ‘primer’ of a few chapters.

  9. I´ve read the first edition and really liked it. You´re TOC for the second one looks nice, although I would like “Applications for dynamic code” to be it´s own chapter so you can give more examples where to use it. Something like:
    1. Basic usages
    2. Does and dont´s
    3. Advanced usages
    4. On the Horizon(stuff thats really out there…)

    finally a I´d love to see a something on language interop with ruby/phyton/f#, but i´m not sure it would fit in well with the rest of the book

  10. There are not enough books for experienced developers as it is – I’d love it if you kept the beginner stuff out of yours.

  11. I have not read C# In Depth, as I already have many C# books covering the current version. However, if you release the 2nd edition around the RTM of VS2010, I will definitely be one of your first customers.

    The outline above looks great. The only thing I’d like to see is something on performance, including the testing thereof. I really like your posts on performance testing, and I think some guidance to developers of all levels on how to check and tweak their algorithms with specific reference to C# and .NET would be very valuable.

  12. For someone in the 2nd category (haven’t read the first book / several years of C# .NET experience), I assess books like this on a quality content per page basis. That said, part one should be very brief (doesn’t need a history of C#), and I’d think part 2 should be streamlined from the first version so that the focus could be on newer things. Looks like there is plenty of newer content to cover that certainly looks promising. At 424 pages, the current release is pushing the typical length limit for me (I’ll only by a 600 page book if it is written by Donald Knuth), so I’d be less likely to buy the book if it stretched out much longer. Anyhow, thanks for the excellent blog posts. I’ll look forward to checking out the 2nd edition in the future.

  13. A writer said “the good book is the book that every time you read it you pick something new”, and C# in depth as it’s now is from this kind of books. I already read it two times (referring to it time to time not counted) and every time I feel I had not read it yet.
    but for new version of it and from table of contents it seems very promising, but the most important thing is “C# in depth first edition” had made a standard level for writing books so if you can’t exceed it please please please keep this level as it’s and the most factor is don’t change the content to target new audience. So please don’t let down people had loved you.

  14. I would be excited to see a new edition that is a completely separate book and focuses completely on C# 4. I too am a fan of slim books.

  15. I’ll join the chorus of those urging you to … please … NOT! … to try to cater any more to the newbie set …

    frankly speaking … I know those books sell and sell well! … and thats got to be a powerful motivator … but we (working developers) and they (when they become working developers) NEED books like yours … books that teach details and ‘raise your game’ as a dev … which your book does in a superior job of. IMHO.

    To me, CS4 is not a major new release. It fixes some irritating issues (optional and named parameters, covarance/contravariance) and allows better interop with other .Net languages.

    Your approach in the TOC above, as usual, is quite thorough. I think the real mind bending release is gonna be CS5. When I’m sure we’ll get an actors library (or two) and maybe TPL and CCR baked into the language … and some sort of immutability contructs .. my head hurts already.

    Hopefully the JCP can get something similar done in a similar time frame so I dont have to start learning Scala … but thats another rant!

    Anyway … youve already sold one copy of the new book when it comes out.

  16. my 2p =

    C# in depth is an exceptional mid level programming book. If you try to cater for newbies the book will lose its appeal in this respect. It is called “in depth” after all.

    With regards to the content: I will buy the new edition either way. The slim form of the book was refreshing but I wouldn’t regard thickness a deal breaker. I reckon the new TOC looks good and a bit of growth wouldn’t hurt any.

    Looking forward to it

  17. Jon,

    I agree with Joel Coehoorn, baseline at C# 2 not C# 1, in my view you shouldn’t even mention non-generic collections.

    I don’t think a reference book for C# 4 should contain C# 5 speculation as the book may still be in use at the time of C# 5 but the speculation incorrect.

    I don’t think F# should get it’s own sub-chapter, but do think things like Parallel Extensions (if they map well to C# 4) should be included after any discussion of threading (not at the end of the book).

    Ray

  18. ++ c# 2.0 baseline (a simple mention of classes/namespaces which are now totally deprecated is enough)

    ++ remove f# you can’t do it justice without adding vast amounts of text and Expert f# is awesome anyway. I would simply point out that for those that have enjoyed the 3.0 changes providing more functional constructs taking a look at the new first class .net language in 2010 release would be a good idea.

    I would suggest that dealing with some of the *interactions* of the newer code constructs is a good idea. Mixing dynamic with optional arguments will be a world of confusion (perhaps with a dashing of covariance for fun :)

  19. I’m going to respond to all these comments when I get a chance, but if those asking for a “C# 2.0 baseline” could explain *exactly* what they mean, that would be helpful. I already start off with C# 2, except to go over three specific topics from C# 1 which are often misunderstood.

    There’d be the possibility of taking that one step further and *assuming* C# 2 knowledge, but in my experience people are still pretty hazy on some of the concepts from C# 2, particularly generics. I think I’d rather keep the C# 2 material in there.

    As for F# – perhaps instead of talking about F# the language, I should merely talk about some of the more functional types which will be available, such as Tuple.

    Jon

  20. Keep the C# 2 content. It’s already written, it’s going to be useful to some people, and it does cover some complex subjects that even working C# 2 programmers could use a refresher in. People who aren’t interested can simply skip the chapter so I’m not sure why anyone would want it dropped.

  21. Hi Jon,
    I read the book already, and I love it.
    One thing I would really find valuable to have in the 2nd edition covering C# 4 is to be able to catch up with the new language features and changes without having to read the whole book again. I am pretty sure most of the people who read the first edition would like the idea.
    Thanks for the hard work,
    pejvan (at gmail)
    PS: where to place the pre-order? ;-)

  22. Jon,

    Good to hear that you will update the book for C# 4.

    I think that your first books focus on only the C# 3 language and its separation of concerns for items such as the BCL and general CLR issues was one of the specific reasons why your first book was concise and had depth.

    Having said that I would think that any deviations outside of introducing those missing items not covered from The C# Programming Language, 3rd Edition, (more specifically topics such as attributes and unsafe code) in addition to the new items that will be in the The C# Programming Language, 4th Edition, should be supplementary material on the website and not in the book.

    For example what would you think if you bought an “in depth” book on one language only to be given a shallow introduction to another language?

    I agree with Dijkstra who asserted that to study in depth an aspect of one’s subject matter in isolation for the sake of its own consistency is the separation of concerns principle.

    Just my 2 cents for your consideration.

    Best Regards,

    Anthony

  23. One of the features I’m most looking forward to is code contracts. I believe these will make a large difference in the ability to write code with fewer bugs.

    I would like to see this be a bit deeper than just a final section in the C# 4 area.

    At a personal preference level, I don’t really like to see the book broken down by “C# 2, 3, 4″. As I alread know C# 2 & 3, this would mean I’m only buying 33% of the book…

    I would prefer to see this as a C#4 book, and in turn broken down by functional areas. The content is all the same, but the arrangement would be slightly different as a result.


    Chris

  24. Chris,

    I’m trying to see what I can do about the “only buying 33% of the book” issue – but isn’t it useful to be able to read that 33% directly, knowing that *this* is the bit containing the new stuff, and then have the rest of the book as reference for a later date?

    I would have expected that to be more useful than having to pick through individual topics throughout the whole book to find the stuff you’re really interested in (the new bits).

    (Responses to the rest of the comments coming when I have time, btw… sorry, I’m really snowed under right now!)

    Jon

  25. Already working on the next revision, are you? You wouldn’t have this problem if your language was designed by committee ;)

    Anyway, a possible title for Part 4 might be “Rapid Development in an e-Fulfillment World” b/c that seems to be a lot of the motivation for dynamic typing.

  26. Jon, a rather offtopic question:
    I would like to know how you usually name private class fields in C#. Do you prefer

    string _myField;

    or

    string myField;

    I believe the C# coding guidelines suggest the latter variant. However when I open up various Microsoft assemblies using Reflector, I mostly see the first variant, sometimes even hungariant notation like m_myField :/ What is your opinion on this?

  27. @drian: Personally I tend to use the latter. I’ve used “m_myField” (which isn’t really Hungarian, btw) in previous jobs, but never found it particularly helpful. Underscores tend to form a mental obstacle to the way I read code.

  28. Less is definitely more. I’d rather re-read a book that puts it succinctly than try to find the real information in endless wads of blubber.

  29. I’m in group #3.

    “what might persuade you to buy the second edition?”
    “new stuff” as you suggest in your second question:

    “How much “new” stuff is required?”
    There has to be some sort of “tree killer” test here since I probably won’t need anything that’s in the 1st ed. 30-50% new content?

    “[..] significantly thicker book, or does the relative slimness of C# in Depth hold real appeal?”
    ‘Slim’ is actually of enormous appeal to me (coming from a generation of 550 page programming books). I immediately recognized that this book was compact and to the point for a targeted audience, rather than a catch-all tome. I can actually carry this book on the subway.

    “The second edition certainly will be thicker [...]”
    I think that’s unfortunate. I’d rather see a “Part II” than a “Director’s Cut”. Is a whole new book focusing just on C# 3/4 possible?

  30. On the subway this morning reading C# in Depth, Chapter 8. Woman next to me in business suit and smart glasses, who’d been looking over my shoulder for the last 5 pages, as I was getting off: “what book were you reading? I was trying to recognize just one word to figure out what it was about.”

  31. I’ve read and enjoyed c# in depth because it was well written, informative and (importantly) slim. I wouldn’t hesitate to buy a “volume 2″ style book that builds on the current book, rather than reiterating big sections. Not sure i’d buy a big thick book, as i’ve already got loads of those to plough through

  32. Just got an email from Manning announcing the 2nd edition and offering 60% discount code for the book (meap + ebook/softbound)! Make sure not to let this one go in your trash :)

    I just pre-ordered mine! Can’t wait!

  33. I really enjoyed the first edition and I think I would probably buy the second edition (unless I’d already read the new bits online :).

    A lot of what I read in the first edition was already familiar to me (probably from reading your web posts and my own usage). Strangely, the thing that really jumped out at me was that little real-world example of using Linq to read all the log files in a directory in three lines of code.

    I know that the usage and application of C# is not what the book is about, and it would also be difficult or overly selective to choose real-world examples, but a chapter of neat usages gleaned from your own experience or from questions on Stack Overflow, might help a lot of developers find a shortcut to good practice.

    So a chapter called ‘C# in Practice’ or ‘C# in Common Scenarios’ might be useful, especially if it was conceptually continuous with the earlier discussions of language features and exemplified them with likely and usable examples.

  34. @Rob: I’ll probably be expanding that log file scenario in the second edition – I really like it too :)

    I do like the idea of “C# in Practice” but I’m not sure that it quite fits into the book itself. I suspect it would work very well as a free companion ebook though. The one trouble is that I’m really bad at creating realistic examples! Hopefully I’m improving though…

Comments are closed.