Preface
This Learning Path shows you how to create high performing applications and solve programming challenges using a wide range of C# features. You’ll begin by learning how to identify the bottlenecks in writing programs, highlight common performance pitfalls, and apply strategies to detect and resolve these issues early. You'll also study the importance of micro-services architecture for building fast applications and implementing resiliency and security in .NET Core. Then, you'll study the importance of defining and testing boundaries, abstracting away third-party code, and working with different types of test double, such as spies, mocks, and fakes. In addition to describing programming trade-offs, this Learning Path will also help you build a useful toolkit of techniques, including value caching, statistical analysis, and geometric algorithms. This Learning Path includes content from the following Packt products:
- C# 7 and .NET Core 2.0 High Performance by Ovais Mehboob Ahmed Khan
- Practical Test-Driven Development using C# 7 by John Callaway, Clayton Hunt
- The Modern C# Challenge by Rod Stephens
Who this book is for
If you want to improve the speed of your code and optimize the performance of your applications or you are looking for a practical resource on test driven development, this is just the Learning Path for you. Some familiarity with C# and .NET will be beneficial for you.
What this book covers
Chapter 1, What's New in .NET Core 2 and C# 7?, discusses the .NET Core Framework and covers some improvements that were introduced with .NET Core 2.0. We will also look into the new features of C# 7 and see how we can write cleaner code and simplify syntactic expressions. Lastly, we cover the topic of writing quality code. We'll see how we can leverage the Code Analysis feature of Visual Studio 2017 to add analyzers to our project and improve code quality.
Â
Chapter 2, Understanding .NET Core Internals and Measuring Performance, discusses the core concepts of .NET Core, including the compilation process, garbage collection, building highly-performant .NET Core applications utilizing multiple cores of the CPU, and publishing an application using a release build. We will also explore the benchmarking tool that is highly used for code optimization and provides results specific to in-memory objects.
Chapter 3, Multithreading and Asynchronous Programming in .NET Core, explores the core fundamentals of multithreaded and asynchronous programming. The chapter starts with the basic differences between multithreaded and asynchronous programming and walks you through the core concepts. It explores APIs and how to use them when writing a multithreaded application. We will learn how the Task Programming Library can be used to serve asynchronous operations, and how to implement the Task Asynchronous pattern. Lastly, we will explore parallel programming techniques and some of the best design patterns being used.
Chapter 4, Securing and Implementing Resilience in .NET Core Applications, takes you through resiliency, which is a very important factor when developing highly-performant applications in .NET Core. We will learn different policies and use the Polly framework to use those policies in .NET Core. We will also learn about safe storage mechanisms and how to use them in the development environment in order to keep sensitive information separate from the project repository. At the end of this chapter, we will learn some security fundamentals, which include SSL, CSRF, CORS, security headers, and the ASP.NET Core Identity framework, in order to protect ASP.NET Core applications.
Chapter 5, Why TDD is Important, asks what is TDD and why should you care? In this chapter, you will learn what TDD is and why it matters. A compelling argument for TDD will be made and the benefits, and more importantly, the execution will be shown.
Chapter 6, Setting Up the .NET Test Environment, explains how to set up your IDE and configure the testing framework so that you can easily run your tests in C# and .NET, with more detail and many more examples of growing complexity in the Speaker Meet API.
Chapter 7, Setting Up a JavaScript Environment, configures the JavaScript testing framework so that you can easily run your tests in your IDE. It provides more detail and many more examples of growing complexity in the Speaker Meet React application.
Chapter 8, What to Know Before Getting Started, dives deeper into the why and how of TDD. You will learn the importance of defining and testing boundaries and abstracting away third-party code (including the .NET Framework), and you'll discover more advanced concepts such as spies, mocks, and fakes, and how to avoid pitfalls along the way.
Â
Â
Chapter 9, Tabula Rasa - Approaching an Application with TDD in Mind, explains how to get started with a new application. You'll apply what you've learned in the previous chapters and take the same approach with a full-sized application using Speaker Meet as an example.
Chapter 10, Testing JavaScript Applications, focuses on creating a Single Page Application in JavaScript using React. It focuses on test-driven actions and reducers and any functionality within the application.
Chapter 11, Exploring Integrations, explains how to write integration tests to ensure that your application is functioning properly.
Chapter 12, Changes in Requirements, focuses on what happens when the requirements change. What happens if a bug is discovered? No problem, change a test or write a new one to cover the new requirement or to defend against the discovered bug. Now, write some new code or change some existing code to make all of the new/modified tests pass. If you do everything correctly, you should feel safe to make these changes as your existing test suite will prevent you from introducing new bugs.
Chapter 13, The Legacy Problem, explains that there are a lot of applications out there without sufficient (any?) test coverage, and even fewer were written test-first. You'll discover some of the major problems with legacy applications that weren't written with testability in mind; they will be identified, and also how best to recover will be covered.
Chapter 14, Unraveling a Mess, dives into how to go about safely modifying a legacy application that wasn't written with testing in mind. How can you add tests to minimize the potential for introducing new bugs when modifying the existing code? An extreme example will be used to explore these topics and more.
Chapter 15, Geometry, presents problems that perform geometric calculations. These ask you to find values such as the roots of equations, the points where lines and circles intersect, and the areas of polygons. Many of these problems ask you to draw shapes such as lines, circles, arrowheads, polygons, and stars.
Chapter 16, Randomization, poses problems that use randomization to produce various kinds of randomized data. For example, they ask you to generate random floating point numbers within a range, pick random items from a list or array, and generate random passwords.
Â
Chapter 17, Files and Directories, covers problems that deal with the filesystem. Its problems ask you to remove blank lines from a file, calculate a directory's total size, detect duplicate files, and generate thumbnails for image files in a directory.
Chapter 18, Advanced C# and .NET Features, includes problems that deal with more advanced features such as Language Integrated Query (LINQ), Parallel LINQ (PLINQ), Transact Parallel Library (TPL), and the yield statement.
Chapter19, Cryptography, describes cryptographic problems. Some, such as the problems that deal with Caesar and Vigenère ciphers, are interesting mostly for fun and historical perspective. Others, such as those that deal with prime numbers, hashing, and string encryption, demonstrate strong, modern cryptographic methods.
To get the most out of this book
To start using this book, you will need the following software installed on your local desktop:
- Visual Studio 2017 or Visual Studio Code
- Linux distro
- InfluxDB
- Grafana
- .NET Core 2.0
Download the example code files
You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packt.com/support and register to have the files emailed directly to you.
You can download the code files by following these steps:
- Log in or register at www.packt.com.
- Select the
SUPPORT
tab. - Click on
Code Downloads & Errata
. - Enter the name of the book in the
Search
box and follow the onscreen instructions.
Â
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
- WinRAR/7-Zip for Windows
- Zipeg/iZip/UnRarX for Mac
- 7-Zip/PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Improving-your-C-Sharp-Skills. In case there's an update to the code, it will be updated on the existing GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Conventions used
There are a number of text conventions used throughout this book.
CodeInText
: Indicates code words in the text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The input()
method is used to get an input from the user."
A block of code is set as follows:
private int FindError(string string1, string string2) { int error = 0; for (int i = 0; i < string1.Length; i++) error += Math.Abs((int)string1[i] - (int)string2[i]); return error; }
Any command-line input or output is written as follows:
Install-Package App.Metrics Install-Pacakge App.Metrics.AspnetCore.Mvc
Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "If you need something different, click on the DOWNLOADS link in the header for all possible downloads: "
Â
Note
Warnings or important notes appear like this.
Note
Tips and tricks appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com
.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packt.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.
Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com
with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!
For more information about Packt, please visit packt.com.