BOOK REVIEW: Effective C#, Second Edition [Addison Wesley]

Peter reviews Bill Wagner's latest title, Effective C#

When I first started reading this book, my initial impression was that it was somewhat simplistic. But when I continued past the first few items, that impression quickly disappeared. I've been using C# since the very first edition of .NET and Visual Studio which was distributed at the PDC 2000 in Orlando. I continue to read books on the language to hone and improve my skills, but this is the first of Bill Wagner's books I've read, and it is really first -rate.

Bill has identified 50 different areas in which you can improve your usage of the C# language, and this includes new features of C# 4.0. This is not a language tutorial book - you can get that from other books. What it does instead is to focus on important specific areas and provide solid, concrete concepts and techniques to help you improve your coding style and technique. For me, that started with item #4, "Use conditional Attributes" -- something that up to now, I have not done.

As you progress through the book, you'll probably want to earmark certain areas that you'll want to be able to refer back to in the near future for further study.

Among other notable inclusions, the section on "Smaller Functions" and the JIT'er really opened my eyes and made me start to think.

Just to give you a quick overview of the content "by example" I reproduce the Table of Contents below:

Chapter 1: C# Language Idioms 1
Item 1: Use Properties Instead of Accessible Data Members 1
Item 2: Prefer readonly to const 8
Item 3: Prefer the is or as Operators to Casts 12
Item 4: Use Conditional Attributes Instead of #if 20
Item 5: Always Provide ToString() 28
Item 6: Understand the Relationships Among the Many Different Concepts of Equality 36
Item 7: Understand the Pitfalls of GetHashCode() 44
Item 8: Prefer Query Syntax to Loops 51
Item 9: Avoid Conversion Operators in Your APIs 56
Item 10: Use Optional Parameters to Minimize Method Overloads 60
Item 11: Understand the Attraction of Small Functions 64

Chapter 2: .NET Resource Management 69
Item 12: Prefer Member Initializers to Assignment Statements 74
Item 13: Use Proper Initialization for Static Class Members 77
Item 14: Minimize Duplicate Initialization Logic 79
Item 15: Utilize using and try/finally for Resource Cleanup 87
Item 16: Avoid Creating Unnecessary Objects 94
Item 17: Implement the Standard Dispose Pattern 98
Item 18: Distinguish Between Value Types and Reference Types 104
Item 19: Ensure That 0 Is a Valid State for Value Types 110
Item 20: Prefer Immutable Atomic Value Types 114

Chapter 3: Expressing Designs in C# 125
Item 21: Limit Visibility of Your Types 126
Item 22: Prefer Defining and Implementing Interfaces to Inheritance 129
Item 23: Understand How Interface Methods Differ from Virtual Methods 139
Item 24: Express Callbacks with Delegates 143
Item 25: Implement the Event Pattern for Notifications 146
Item 26: Avoid Returning References to Internal Class Objects 154
Item 27: Prefer Making Your Types Serializable 157
Item 28: Create Large-Grain Internet Service APIs 166
Item 29: Support Generic Covariance and Contravariance 171

Chapter 4: Working with the Framework 179
Item 30: Prefer Overrides to Event Handlers 179
Item 31: Implement Ordering Relations with IComparable<T> and IComparer<T> 183
Item 32: Avoid ICloneable 190
Item 33: Use the new Modifier Only to React to Base Class Updates 194
Item 34: Avoid Overloading Methods Defined in Base Classes 198
Item 35: Learn How PLINQ Implements Parallel Algorithms 203
Item 36: Understand How to Use PLINQ for I/O Bound Operations 215
Item 37: Construct Parallel Algorithms with Exceptions in Mind 220

Chapter 5: Dynamic Programming in C# 227
Item 38: Understand the Pros and Cons of Dynamic 227
Item 39: Use Dynamic to Leverage the Runtime Type of Generic Type Parameters 236
Item 40: Use Dynamic for Parameters That Receive Anonymous Types 239
Item 41: Use DynamicObject or IDynamicMetaObjectProvider for Data-Driven Dynamic Types 243
Item 42: Understand How to Make Use of the Expression API 254
Item 43: Use Expressions to Transform Late Binding into Early Binding 261
Item 44: Minimize Dynamic Objects in Public APIs 267

Chapter 6: Miscellaneous 275
Item 45: Minimize Boxing and Unboxing 275
Item 46: Create Complete Application-Specific Exception Classes 279
Item 47: Prefer the Strong Exception Guarantee 284
Item 48: Prefer Safe Code 294
Item 49: Prefer CLS-Compliant Assemblies 298
Item 50: Prefer Smaller, Cohesive Assemblies 303

Effective C# - 50 Specific Ways to Improve Your C# is not a big book - it's 328 pages including index. But it is loaded with valuable information that you'll use and refer back to frequently. This book is designed for intermediate to advanced level C# programmers - novices will find the content too challenging to be of immediate use.

I recommend this book to any professsional C# programmer beyond the beginner level who wants to advance their knowledge and skill. As with books like "C# 4.0 In a Nutshell", Bill's book has earned the right to sit on my desk so that I can grab it quickly. Sticker price, $39.99.

By Peter Bromberg   Popularity  (2765 Views)