Book Review: Effective C#
Filed Under Book ReviewsAlthough not his first book on C#, Bill Wagner really became noticed in the .NET community after writing Effective C#: 50 Specific Ways to Improve Your C#.
First off, this is not a C# reference guide. Instead, this is a collection of concrete arguments for using particular C# structures over their counterparts.
The greatest thing I appreciated is that Wagner shows cold, hard evidence for every tip. The cornerstone throughout the book is showing what occurs at compile time in C# and IL examples, and then continuing to explain what occurs at run-time. As an example, Item 11: Prefer foreach loops goes into great depth why the foreach loop is the more effiecient than do, while, and most hand-written for loops.
Perhaps the biggest performance tip I personally received came right away, Item 3: Prefer the is and as operators to casting. Which way would you rather write it?
object o = Factory.CreateInstance(); //Version 1: MyType t = o as MyType; if (t != null) return t.MyValue; //Version 2: if (o is MyType) return (o as MyType).MyValue; //Version 3: try { MyType t = (MyType) o; if (t != null) return t.MyValue; } catch (Exception) { //report a cast exception }
Chapter List
- C# Language Elements
- .NET Resource Management
- Expressing Designs with C#
- Creating Binary Components
- Working with the Framework
- Miscellaneous
The Good
- Quick & easy read
- Solid rationale for every tip
- Basic concepts still applicable after .NET 3.0
- C# veterans and newbies can all learn something from this book
The Bad
- Large number of typos
- A few items are debatable (i.e. Item 41: Prefer DataSets to Custom Structures)
- Does not encompass C# 2.0 or above
- Last chapter titled Miscellaneous was weak. Should have been called 44 Ways To Improve Your C# + 6 Other Tips
I highly recommend this book as I learned a number of great tips that I still use today. It is a fun and quick read that anyone wanting to improve their C# will enjoy. With or without typos, I would give it a 4.
Effective C#: 50 Specific Ways to Improve Your C#
Notice: All reviews on codesqueeze are not paid nor are traded for services. These reviews are shared so you may save time in your quest for better tools.
Refactorbation
Filed Under Thought Stuffre·fac·tor·ba·tion – [re-fak-ter-bey-shuhn]
–noun
- To stimulate oneself through endless refactoring exercises towards unattainable perfection
Synonyms: codesterbation
Like everyone young and dumb, there was a time I would refactorbate all the time. The majority of the time I would refactorbate at night, but occasionally in the morning as well. I knew at some level it was healthy, but at the rate I was going I was sure to grow hair on my keyboard.
Now I am older and wiser. I know how to better architect solutions, and I know when to quit refactoring and ship. Sometimes I still do…just for fun…when no one is looking.
But I am very surprised when I watch some of my peers brag about refactorbating. I wince at comments such as “I put 9 overloads on that method just in case someone ever needed them…”. Gross, keep it at home.
That is why I was happy to see this quote from a post called Perfection: Necessary Act
The real trick is in knowing the difference between an act of perfection and an act of codesterbation. When you stop making things better for either solubility, expressiveness, or testability, and you’re still refactoring, you might be in the weeds. – Scott Belware
If you are refactoring to solve problems you don’t yet have, you are refactorbating. Knock it off, your mother might be crying somewhere.