Clean Code
Even bad code can function. But if code isn't clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn't have to be that way.
Noted software expert Robert C. Martin presents a revolutionary paradigm with Clean Code: A Handbook of Agile Software Craftsmanship. Martin has teamed up with his colleagues from Object Mentor to distill their best agile practice of cleaning code "on the fly" into a book that will instill within you the values of a software craftsman and make you a better programmer—but only if you work at it.
What kind of work will you be doing? You'll be reading code—lots of code. And you will be challenged to think about what's right about that code, and what’s wrong with it. More importantly, you will be challenged to reassess your professional values and your commitment to your craft.
Clean Code is divided into three parts. The first describes the principles, patterns, and practices of writing clean code. The second part consists of several case studies of increasing complexity. Each case study is an exercise in cleaning up code—of transforming a code base that has some problems into one that is sound and efficient. The third part is the payoff: a single chapter containing a list of heuristics and "smells" gathered while creating the case studies. The result is a knowledge base that describes the way we think when we write, read, and clean code.
Readers will come away from this book understanding:
- How to tell the difference between good and bad code
- How to write good code and how to transform bad code into good code
- How to create good names, good functions, good objects, and good classes
- How to format code for maximum readability
- How to implement complete error handling without obscuring code logic
- How to unit test and practice test-driven development
This book is a must for any developer, software engineer, project manager, team lead, or systems analyst with an interest in producing better code.
Review By: Andrew Sheehan
03/30/2009Does writing code come naturally? Today's programming languages, with their latest constructs and improvements, does help one write better code. Added to that are the integrated development environments (IDEs) that provide code assistance, drop-in patterns, and even spell checking. Yet it isn't enough. Having a tool write code is one thing, but you still need to apply artistic thought in a disciplined manner. This book describes essential aspects pertinent to every language, such as ActionScript, C#, Java or Ruby, and is easy to read—unlike most books in this category.
Reading through these chapters brought to mind most of the code I've seen as well as written. The author takes a partner-by-your-side point of view as he discusses major topics of interest in software engineering, as well as brings to light the seemingly minor infractions that are really analogous to the "one broken window" idiom.
This book is a good read. As you peruse through the chapters, you may immediately get the sense that you need to go back to your own code and see where you can improve upon it, if you are as passionate as writing elegant code as is the author.
There are books of various sorts on every developers' desk. Only some are useful. Most are used as much as the treadmill in the basement. The one day I had this book in my cube it was interesting to note that most developers around me asked, "Is it a good "book?" I was more than willing to talk and recommend it, with the caveat that they get their own copy.
Of interest to me was the author's thoughts on the relatively harmless use of comments and how dangerous they really are. Comments really do not change with the code as it goes though its natural revisions. More to the point, if you find yourself writing comments more often than code, you should take a step back and rethink what you are trying to accomplish.
I couldn't think of one good reason to not recommend this book to someone who does commercial or work-for-hire in the development world. Newcomers to the art should read this book as they begin their journey towards code craftsmanship.