Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Clean Code with C#

You're reading from   Clean Code with C# Refactor your legacy C# code base and improve application performance using best practices

Arrow left icon
Product type Paperback
Published in Dec 2023
Publisher Packt
ISBN-13 9781837635191
Length 492 pages
Edition 2nd Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jason Alls Jason Alls
Author Profile Icon Jason Alls
Jason Alls
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

Preface 1. Chapter 1: Coding Standards and Principles in C# 2. Chapter 2: Code Review – Process and Importance FREE CHAPTER 3. Chapter 3: Classes, Objects, and Data Structures 4. Chapter 4: Writing Clean Functions 5. Chapter 5: Exception Handling 6. Chapter 6: Unit Testing 7. Chapter 7: Designing and Developing APIs 8. Chapter 8: Addressing Cross-Cutting Concerns 9. Chapter 9: AOP with PostSharp 10. Chapter 10: Using Tools to Improve Code Quality 11. Chapter 11: Refactoring C# Code 12. Chapter 12: Functional Programming 13. Chapter 13: Cross-Platform Application Development with MAUI 14. Chapter 14: Microservices 15. Assessments 16. Index 17. Other Books You May Enjoy

What this book covers

Chapter 1, Coding Standards and Principles in C#, contrasts some good code with some bad code. As you read through this chapter, you will come to understand why you need coding standards, principles, methodologies, and code conventions. You will learn about modularity and the KISS, YAGNI, DRY, SOLID, and Occam’s razor design guidelines.

Chapter 2, Code Review – Process and Importance, takes you through the code review process and provides reasons for its importance. In this chapter, you are guided through the process of preparing code for review, leading a code review, knowing what to review, knowing when to send code for review, and how to provide and respond to review feedback.

Chapter 3, Classes, Objects, and Data Structures, covers the broad topics of class organization, documentation comments, cohesion, coupling, the Law of Demeter, and immutable objects and data structures. By the end of the chapter, you will be able to write code that is well organized and only has a single responsibility, provide users of the code with relevant documentation, and make the code extensible.

Chapter 4, Writing Clean Functions, helps you to understand functional programming, how to keep methods small, and how to avoid code duplication and multiple parameters. By the time you finish this chapter, you will be able to describe functional programming, write functional code, avoid writing code with more than two parameters, write immutable data objects and structures, keep your methods small, and write code that adheres to the single responsibility principle.

Chapter 5, Exception Handling, covers checked and unchecked exceptions, and NullPointerException, and how to avoid them as well as covering, business rule exceptions, providing meaningful data, and building your own custom exceptions.

Chapter 6, Unit Testing, takes you through using the Behavior-Driven Development (BDD) software methodology using SpecFlow, and Test-Driven Development (TDD) using MSTest and NUnit. You will learn how to write mock (fake) objects using Moq, and how to use the TDD software methodology to write tests that fail, make the tests pass, and then refactor the code once it passes.

Chapter 7, Designing and Developing APIs, helps you to understand what an API is, and covers API proxies, API design guidelines, API design using RAML, and Swagger API development. In this chapter, you will design a language-agnostic API in RAML and develop it in C#, and you will document your API using Swagger.

Chapter 8, Addressing Cross-Cutting Concerns, introduces you to using PostSharp to address cross-cutting concerns using aspects and attributes that form the basis of aspect-oriented development. You will also learn how to use proxies and decorators.

Chapter 9, AOP with PostSharp, explores using PostSharp to implement Aspect-Oriented Programming (AOP). With our AOP framework, we will learn how to manage common functionalities such as exception handling, logging, security, and transactions within our applications. But before that, let’s put your brain to work to see what you have learned.

Chapter 10, Using Tools to Improve Code Quality, exposes you to various tools that will assist you in writing quality code and improving the quality of existing code. You’ll gain exposure to code metrics and code analysis, quick actions, the JetBrains tools called dotTrace Profiler and Resharper, and Telerik JustDecompile.

Chapter 11, Refactoring C# Code, is the first of two chapters that take you through different types of problematic code and show you how to modify it to be clean code that is easy to read, maintain, and extend. Code problems are listed alphabetically through each chapter. Here, you will cover such topics as class dependencies, code that can’t be modified, collections, and combinatorial explosion.

Chapter 12, Functional Programming, provides a detailed look at functional programming. You will learn the difference between imperative and functional programming. Then you will learn about delegates, anonymous methods, and lambda expressions Next, you move on to the topics of asynchronous functional programming, recursion, and then finally, pattern matching.

Chapter 13, Cross-platform development with MAUI, delves into building applications with .NET MAUI. You will learn the differences between the older Xamarin.Forms and the newer MAUI, including using UI controls using the MVVM pattern, data binding, access device resources, data access accessing remote microservices and Azure Functions, dependency injection, and styling.

Chapter 14, Microservices, looks at developing microservices using Azure Functions.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image