Book description
Learn how to improve the maintainability of C# code using modern tools and techniques to resolve technical debt while working safely and efficiently with legacy code
Key Features
- Apply a wide range of refactoring techniques using the latest tools and features of C#
- Discover ways to safely improve your code using tests, Roslyn analyzers, and AI assistance
- Find ways of communicating technical debt and improving your code in agile and enterprise settings
- Purchase of the print or Kindle book includes a free PDF eBook
Book Description
Software projects start as brand-new greenfield projects, but invariably become muddied in technical debt far sooner than you’d expect. In Refactoring with C#, you'll explore what technical debt is and how it arises before walking through the process of safely refactoring C# code using modern tooling in Visual Studio and more recent C# language features using C# 12 and .NET 8. This book, written by a Microsoft MVP, will guide you through the process of refactoring safely through advanced unit testing with XUnit and libraries like Moq, Snapper, and Scientist .NET. You'll explore maintainable code through SOLID principles and defensive coding techniques made possible in newer versions of C#. You'll also find out how to run code analysis and write custom Roslyn analyzers to detect and resolve issues unique to your code.
The nature of coding is changing, and you'll explore how to use AI with the GitHub Copilot Chat to refactor, test, document, and generate code before ending with a discussion about communicating technical debt to leadership and getting organizational buy-in to refactor your code in enterprise organizations and in agile teams.
By the end of this book, you'll understand the nature of refactoring and see how you can safely, effectively, and repeatably pay down the technical debt in your application while adding value to your business.
What you will learn
- Understand technical debt, its causes and effects, and ways to prevent it
- Explore different ways of refactoring classes, methods, and lines of code
- Discover how to write effective unit tests supported by libraries such as Moq
- Understand SOLID principles and factors that lead to maintainable code
- Use AI to analyze, improve, and test code with the GitHub Copilot Chat
- Apply code analysis and custom Roslyn analyzers to ensure that code stays clean
- Communicate tech debt and code standards successfully in agile teams
Who this book is for
This book is for any developer familiar with C# who wants to improve the code they work with on a day-to-day basis. While this book will be most beneficial to new developers with only a year or two of experience, even senior engineers and engineering managers can make the most of this book by exploring not just the process of refactoring, but advanced techniques with libraries like Moq, Snapper, Scientist .NET, and writing custom Roslyn analyzers.
Table of contents
- Refactoring with C#
- Foreword
- Contributors
- About the author
- About the reviewers
- Preface
- Part 1: Refactoring with C# in Visual Studio
- Chapter 1: Technical Debt, Code Smells, and Refactoring
- Chapter 2: Introduction to Refactoring
- Chapter 3: Refactoring Code Flow and Iteration
- Chapter 4: Refactoring at the Method Level
-
Chapter 5: Object-Oriented Refactoring
- Technical requirements
- Refactoring the flight search system
- Organizing classes via refactoring
- Refactoring and inheritance
- Controlling inheritance with abstract
- Refactoring for better encapsulation
- Improving classes with interfaces and polymorphism
- Reviewing and testing our refactored code
- Summary
- Questions
- Further reading
- Part 2: Refactoring Safely
- Chapter 6: Unit Testing
- Chapter 7: Test-Driven Development
- Chapter 8: Avoiding Code Anti-Patterns with SOLID
- Chapter 9: Advanced Unit Testing
- Chapter 10: Defensive Coding Techniques
- Part 3: Advanced Refactoring with AI and Code Analysis
-
Chapter 11: AI-Assisted Refactoring with GitHub Copilot
- Technical requirements
- Introducing GitHub Copilot
- Getting started with GitHub Copilot in Visual Studio
- Refactoring with GitHub Copilot Chat
- Drafting documentation with GitHub Copilot Chat
- Generating test stubs with GitHub Copilot Chat
- Understanding the limits of GitHub Copilot
- Case study: Cloudy Skies Airline
- Summary
- Questions
- Further reading
- Chapter 12: Code Analysis in Visual Studio
- Chapter 13: Creating a Roslyn Analyzer
- Chapter 14: Refactoring Code with Roslyn Analyzers
- Part 4: Refactoring in the Enterprise
- Chapter 15: Communicating Technical Debt
- Chapter 16: Adopting Code Standards
- Chapter 17: Agile Refactoring
- Index
- Other Books You May Enjoy
Product information
- Title: Refactoring with C#
- Author(s):
- Release date: November 2023
- Publisher(s): Packt Publishing
- ISBN: 9781835089989
You might also like
book
Design Patterns in .NET Core 3: Reusable Approaches in C# and F# for Object-Oriented Software Design
Implement design patterns in .NET Core 3 using the latest versions of the C# and F# …
book
Design Patterns in .NET 6: Reusable Approaches in C# and F# for Object-Oriented Software Design
Implement design patterns in .NET 6 using the latest versions of the C# and F# languages. …
book
Simple and Efficient Programming with C#: Skills to Build Applications with Visual Studio and .NET
Apply skills and approaches to your programming to build a real-world application in C# 11 using …
book
Metaprogramming in C#
Developing software can be very hard and often increasingly harder over time. Within the .NET runtime …