My session is all about how to make your C# code better and to do it more routinely and with high-confidence. Too often, we are afraid to refactor because we might break something--but we err on the side of false caution, because our dirty, confusing code causes more bugs than a refactoring would. I'll show my favorite refactorings and demonstrate how to get into the habit of always improving.
I also am excited to see my colleagues Kamran Ayub, Erik Onarheim, and Elsa Vezino present there, and I always love more Benko-tips and wisdom from Ward. Thanks a ton to Jason Erdahl and his team at ILM for moving this thing online rather than cancelling--I've never been as interested in a live online conference before!
Video: Practical Refactoring in C#
Slides
Demo Code
My favorite refactorings:
- Tool-assisted:
- Rename
- Extract method
- Move
- Remove unused usings
- Reduce nesting: Invert if; combine singly-nested Ifs;
- Extract interface
- Restrict access modifiers
- Code against nonexisting members then generate
- Manual:
- Simplify boolean logic
- Early return
- Reduce newline usage
- Convert If-else to ternary
- Eliminate/simplify loops with LINQ
- Iterate instead of repeat code (try lambdas or private classes)
- Replace Start/Stop methods with an IDisposable
- 7 steps to add dependency injection