inside front cover
Clean Code Checklist
Use this short checklist when encountering code that you are unfamiliar with or while writing new code.
General
My code reads like a narrative. I write code for humans, not machines.
I document my code only when necessary. My code should speak for itself.
I provide clear instructions on how to build and release my codebase. Where appropriate, I provide working build scripts/makefiles or CI/CD setup instructions.
I use native functionalities instead of implementing my own libraries, unless for a very good reason.
My code is consistent in its design patterns, documentation, and naming conventions. I do not change things mid-development and go against established patterns.
I have added logging to my application, so I or other developers can debug when things go awry.
Classes
My class has the strictest access modifier possible.
My class is named accurately.
My class performs operations on only one specific object and, therefore, adheres to the single-responsibility principle.
My class lives in the right folder within my project.
If I struggle with implementing my class, I take a step back and come up with a brief description of the class and its intended functionality. This refocus can help write cleaner code. If my class should do multiple things, split it up.
Methods
My method has the strictest access modifier possible.
My method is named accurately and correctly describes the logic within (leaving nothing out).
My method performs only one general operation or collects information from other methods related to its operations. It adheres to the single-responsibility principle.
If my method has a public access modifier, we do not perform any operations within the method. The public method calls other, smaller, methods and organizes the outputs.
I have unit tests backing my method. The unit tests should cover the major success and failure logic branches.
Continues on inside back cover
Code like a Pro in C#
Jort Rodenburg
To comment go to liveBook
Manning
Shelter Island
For more information on this and other Manning titles go to
www.manning.com
Copyright
For online information and ordering of these and other Manning books, please visit www.manning.com. The publisher offers discounts on these books when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email: orders@manning.com
2021 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
| Manning Publications Co. 20 Baldwin Road Technical PO Box 761 Shelter Island, NY 11964 |
Development editor: | Marina Michaels |
Senior technical development editors: | Eric Lippert and Enrico Buonanno |
Technical development editor: | Jean-Franois Morin |
Review editor: | Mihaela Batini |
Production editor: | Andy Marinkovich |
Copy editor: | Pamela Hunt |
Proofreader: | Katie Tennant |
Technical proofreader: | Tanya Wilke |
Typesetter: | Dennis Dalinnik |
Cover designer: | Marija Tudor |
ISBN: 9781617298028
front matter
preface
My first introduction to C# came when I joined Fujifilm Medical Systems in 2016. I had previous experience in Java and Python, but when C# came around, I did not look back. I loved its low barrier of entry and (at first excruciatingly infuriating) focus on explicit typing. Throughout my time at the company, I annoyed my coworkers with questions about C# and how to best use it. Getting started was easy, but becoming proficient was another matter altogether. Everybody can write a Hello, World application within 10 minutes, no matter their background, but using a language to its fullest strengths while knowing why certain things are implemented the way they are simply takes time. After a while, I felt like I had plateaued in my C# knowledge and was looking for resources to take me to the next level. Quickly, I realized that there were three major types of books dealing with .NET and C#: books about language-transcending topics (clean code, architecture, infrastructure, and the like) that happened to use C#, books on how to start programming using C#, and books that are so advanced that you might just be qualified to become the CTO of Microsoft after reading them. I wanted there to be a book that sat in the middle of all three: a book that deals with clean code and bridges the gap between beginner and advanced topics. That book did not exist, so I wrote it. This is that book.
If you are a software engineer (or developer, or coder, or whatever your title may be) with previous experience in a (preferably object-oriented) programming language and want to jump into C#, this is the book for you. You will not have to learn how to write an if
statement, nor will I explain what an object is to you. What you will find in this book are skills and topics that prepare you for deeper study into the language and platform. Of course, I cant promise to cover everything a more difficult resource assumes you know, but within the limited page count of this book, I sure tried. I very much hope you enjoy this book and learn a thing or two. And if not, well, it never hurts to go over things you know again.
acknowledgments
When I first started talking with Manning about writing this book, I had little idea of how it would take over my life for about a year or so. To be fair, I was warned on multiple occasions that authors tend to underestimate the time needed to write a book. I, being stubborn, thought I would be the exception. I was not. From December 2019 to March 2021, I put many hours into this book. On multiple occasions, I thought to myself that this will surely be the end. Every single time (but one, obviously), it was not. Luckily, I have a very patient wife and plenty of time to kill.
It is with that in mind that I would first like to thank my wife for sticking by me on this roller coaster and to apologize to her for disappearing from her life for a year. I could not have written this book without her unwavering support. She was the rock on which this book was built. I also want to thank my family, who were always very excited to hear about new developments and updates. I took the liberty of naming the CEO of the company in the business case we follow through the book by combining the first name of my maternal grandfather (Aljen) and the surname of my paternal grandmother (van der Meulen).