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 in C#

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

Arrow left icon
Product type Paperback
Published in Jul 2020
Publisher Packt
ISBN-13 9781838982973
Length 500 pages
Edition 1st Edition
Languages
Tools
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 (17) Chapters Close

Preface 1. Coding Standards and Principles in C# 2. Code Review – Process and Importance FREE CHAPTER 3. Classes, Objects, and Data Structures 4. Writing Clean Functions 5. Exception Handling 6. Unit Testing 7. End-to-End System Testing 8. Threading and Concurrency 9. Designing and Developing APIs 10. Securing APIs with API Keys and Azure Key Vault 11. Addressing Cross-Cutting Concerns 12. Using Tools to Improve Code Quality 13. Refactoring C# Code – Identifying Code Smells 14. Refactoring C# Code – Implementing Design Patterns 15. Assessments 16. Other Books You May Enjoy

What this book covers

Chapter 1, Coding Standards and Principles in C#, looks at some good code contrasted with 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 design guidelines KISS, YAGNI, DRY, SOLID, and Occam's razor.

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 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, 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, End-to-End System Testing, guides you through the manual process of end-to-end testing using an example project. In this chapter, you will perform End-to-End (E2E) testing, code and test factories, code and test dependency injection, and test modularization. You will also learn how to utilize modularization.

Chapter 8, Threading and Concurrency, focuses on understanding the thread life cycle; adding parameters to threads; using ThreadPool, mutexes, and synchronous threads; working with parallel threads using semaphores; limiting the number of threads and processors used by ThreadPool; preventing deadlocks and race conditions; static methods and constructors; mutability and immutability; and thread-safety.

Chapter 9, Designing and Developing APIs, helps you to understand what an API is, 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 10, Securing APIs with API Keys and Azure Key Vault, shows you how to obtain a third-party API key, store that key in Azure Key Vault, and retrieve it via an API that you will build and deploy to Azure. You will then implement API key authentication and authorization to secure your own API.

Chapter 11, 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 12, 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 13, Refactoring C# Code – Identifying Code Smells, 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 14, Refactoring C# Code – Implementing Design Patterns, takes you through the implementation of creational and structural design patterns. Here, behavioral design patterns are briefly touched upon. You are then given some final thoughts on clean code and refactoring.

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