Effective C#

Product Description
C# has matured over the past decade: It’s now a rich language with generics, functional programming concepts, and support for both static and dynamic typing. This palette of techniques provides great tools for many different idioms, but there are also many ways to make mistakes. In Effective C#, Second Edition, respected .NET expert Bill Wagner identifies fifty ways you can leverage the full power of the C# 4.0 language to express your designs concisely and… More >>

Effective C#

5 thoughts on “Effective C#”

  1. FULL DISCLOSURE: I know Bill Wagner pretty well, and consider him a friend. I don’t think that has colored this review, but you have a right to know. (If you doubt my objectivity, consider that I have now purchased TWO copies of this book, even though I probably could have gotten one or two for free. It’s worth it!)

    Back when I was a C++ programmer, there was one book everyone said I simply had to read: Effective C++ by Scott Meyers. And they were right: when I read that book, I summarized it as “Here are 50 mistakes you’re making in your C++ code right now, and you don’t even know it.” (Note: the latest edition has been expanded to 55 mistakes.) So now that I’m a C# programmer, I eagerly looked forward to Effective C# (edited by Meyers), because I wanted that same sort of “Aha!” enlightenment.

    Well, Bill Wagner failed to deliver that enlightenment. But that’s a good thing, actually, and something he couldn’t help. But to understand why, we have to return to Scott Meyers.

    After the 50 amazingly simple improvements in Effective C++, Meyers wrote More Effective C++; and I characterized that book as, “35 really deep subjects that you have to think about and understand. Some of them will apply to your work. Some of them won’t. None of them will be easy. But you really have to think about them.” See, Meyers covered all the simple, universal problems in his first book, making it darned hard to make any simple, obvious C++ mistakes. That meant his second book had to cover deeper design concerns, many of which apply only in particular circumstances.

    And herein lies the difference for Wagner’s book. See, a generation of C++ programmers learned and internalized Meyers’s lessons — including the Microsoft team who created the C# language. When they built their C++-inspired (and Java-inspired) language, they built in a lot of the safeguards and limits that Meyers advocated as a standard practice for C++. They also built in best practices from other sources. So it’s my contention that the C# equivalent to Effective C++ can’t really be written. The language won’t allow it.

    So what Wagner has written really falls somewhere between Effective C++ and More Effective C++. There are some simple “Aha!” tips; but there are a lot more deep design concerns. That’s really what the C# programmer needs, after all; and that’s what Wagner delivers in a very fine fashion.

    Now Wagner can explain these topics better than I can, so I’m not going to try. But I do want to comment on the items I found most useful:

    5. Always provide ToString(). Your maintenance and client coders will thank you.

    15. Utilize using and try/finally for Resource Cleanup. And 18. Implement the Standard Dispose Pattern. .NET pretty much solves memory leaks; but memory is only the most commonly leaked resource. And in solving memory leaks, they made it harder to manage certain other resources. In these two items, Wagner shows how to do the best job you can.

    I wish I could say I was following every tip in this book; but it’s hard to break bad habits. Read this book before you form bad habits yourself.

    Note that the original printing of this book had a lot of typos where words rantogether. I now have a copy of the second printing, where those all seem to be fixed.

    Rating: 5 / 5

  2. Wow, what at relief this book is, really.

    I have read numerous C# books and most of them do about the same thing. They touch base on a wide array of topics (database, oop, multi-threading, arrays, indexers…etc), thus you really never learn any of the more advanced stuff. Really, how many times have you read about an animal hierarchy whilst browsing through an OOP section of a programming book?

    Well, in comes Effective C#. This book doesn’t really focus much on specific topics (like how to do database programming and such), instead, you learn 50 specific ways to improve your C# code. For example: You have undoubtedly read about properties if you’ve read any basic C# book… You probably think you know everything there is to know about them… I mean, really, generally we use public properties to access private variables in a class. Well, one of the topics in this book focuses on properties – I never realized how much more there is to learn about something as simple as a property!

    This book is a thinker. You will browse these pages and think to yourself “Wow! I never realized you could do that!”. Your expertise on C# will definitely go up a notch or two. That brings me to my next point: This is no easy read! Even if you feel that you’re at an intermediate level, you will find some of the text difficult to absorb on the first couple passes. This is definitely a techie book through and through (which isn’t all that bad), but at times it may seem slightly dry.

    If you are a beginner then I might pass this book up for a later day. If you are intermediate – advanced then I would definitely think about picking this baby up.
    Rating: 4 / 5

  3. First off, since writing my initial review, I find myself continually referring to this book. It has worn well. I wish I could change my rating from 3 to 4 stars. Unfortunately Amazon’s review system doesn’t allow that (only 3 stars for them!).

    While there are many books that teach the C# languague, this is the only book I’ve found that offers advice on how to effectively use the language once you know it. It is unique and therefore indispensible. It’s a “must-read” for any serious C# programmer.

    The recommendations will help you understand C# so that you can write programs that are faster, more efficient, more maintainable, and easier to understand. Specific topics include things like value-types versus reference-types, “boxing” and “unboxing”, minimizing garbage, the advantages of the operators “as” and “is” over casts, and so on.

    I believe the writing and explanations could be more clear and concise. I wish the editors had spent a little more time cleaning up the text. Also, A second edition that assumes C# 2.0 should be released, since some of the recommendations deal with shortcomings of C# 1.0 that have been fixed by C# 2.0. Also, I found a couple small errors. For example, “as” is not always faster than a cast– in some cases they generate code that is exactly the same speed. However, that’s a trifling point.

    I recommend this book.

    Rating: 3 / 5

  4. This book is a revelation. If you want to improve your code, you need this book. Bill Wagner’s advice is directly contradictory to what you’ll find on the web, but unlike the so-called experts that write those fluffy articles that you find in Google searches, he can actually prove his assertion via ILM disassembly. For instance, he supports the use of the foreach statement, and tells and _shows_ you exactly why it’s the best way to iterate over an aggregate, as opposed to the old for statement, which he also proves is the _worst_ way to do an iteration.

    There are minor quibbles here and there (he occasionally contradicts his own advice in his examples), and I seriously disagree with his recommendation of the DataSet over using your own custom collection classes. But, hey, you’re never going to agree with everything an author has to say, and out of 50 suggestions I can live with one that I don’t agree with.

    Just buy the book and revel in his genius.
    Rating: 5 / 5

  5. I used C++ as my primary language for years. At first, most of the books I read were on the mechanics and rules of the language. Then, books like Effective C++ came along that describe many of the complications you will run into as you use it and provide good guidelines.

    There are many books out there on the mechanics of C# and the .NET framework. However, the language is not yet mature and everyone is still figuring out the best way to use it.

    Effective C# identifies many issues that you’ll run into as a C# developer along with guidelines on how to deal with the issues. As an example, it discusses GetHashCode(), which might seem simple to implement on the face of things, but there are a bunch of complexities. It also have many good topics on issues that arise with value types vs. reference types, like boxing and unboxing. There is a great breadth of topics.

    I think almost everyone will learn something from this book. I wish there was more coverage of exception handling. And, it only has minor coverage of C#/.Net 2.0 – I hope there will be an updated version available because there are many relevant changes. Also, there seemed to be spaces randomly missing throught the book which didn’t take away from the content, but was distracting.

    Rating: 5 / 5

Leave a Reply to Dan Crevier Cancel reply

Your email address will not be published. Required fields are marked *