Foreword

We can learn a great deal from observing others. Suppose you and a woman are walking toward the same building, with you several steps behind. As the woman enters the building, she momentarily holds the door open for you. That’s her expression of empathy and humanity. While she is focused on moving forward, she also cares about the person behind her and wants to make your journey at least a bit pleasant. You are total strangers and may never meet again, and yet she showed benevolence.

Programming is a passion for many, but it also deeply involves empathy and humanity.

When we write code, there is always someone behind us. Sometimes it’s ourselves after a few hours, days, weeks, or months. But it’s often a colleague who comes around to make changes to the code, fix a bug, add a feature, extend the software. To make the code easier for that person to maintain is far beyond an act of benevolence. It’s part of being a professional. It’s part of practicing the craft.

Writing code is easy. Writing good-quality code takes effort, discipline, and a lot of practice. There are many different definitions for code quality. Here’s mine:

Code Quality

The quality of code is inversely proportional to the amount of effort to understand it.

Good code is transparent. It makes the logic obvious to readers so they can get on with their work. Poor code is opaque and hides the logic. The reader has to spend time and effort to figure out the details from badly written code.

When we sit down to program a feature or a particular logic, we’re focused deeply on getting it to work. Programming is a series of mini experiments and discoveries. We often have to devise solutions and approaches to implement the problem at hand. Creating code is but only the first step. Code is written once, but it is read and evolved many times. If the code we create is of poor quality, even if it appears to function flawlessly, we have increased the cost of ownership of that code over time.

Most of the programmers hired to write code will deliver working software. The difference between average programmers and amazing ones is how easy it is for others to follow their work.

Writing good-quality code is a skill. As with any skill, in order to acquire and improve, we have to make a conscious effort, get critiqued, and take the time to learn. With continuous effort, writing good-quality code becomes second nature and will begin to seem effortless. The journey is hard, but at the same time, it’s a wonderful learning experience. Part of that learning can come from reading great books, like the one you’re about to begin.

In the three-plus decades I have been programming, I have made most of the mistakes mentioned in this book. I spend a lot of time these days reviewing code written by students and also by professionals in the industry. I see both students and professionals making many of the same mistakes. As you read this book, you will quickly relate to mistakes that you may have already made. The first step in solving a problem is realizing it. The authors of this book have done a wonderful job of guiding us through the smells, the issues, and the consequences of each bad piece of code. Then they show us ways to avoid the mess, how to write quality code, and the benefits we derive from the better quality.

I urge you not to rush through this book. Sometimes we have to slow down to gain speed. As you move through the book, take time to read each piece of bad code and spend some time identifying things that are wrong. Jot them down. Then read through the authors’ explanations. This will help with better absorption and also help you to develop a sense for quality and style. Then, think through possible solutions, again, before jumping in to read the presented solution and the reasoning.

Writing code is fun. Writing code that is easier to understand and evolve is pure bliss. It is truly a pleasure to see a book written to help aspiring programmers become respectable professionals. Let Simon, Jörg, and Linus be your guides—you’re in good hands.

Let’s turn programming into a wonderful craft.

Dr. Venkat Subramaniam

President, Agile Developer, Inc. March 2018

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.96.105