Recently, I have been talking a lot about writing clean code. Instead of me talking more about it, here’s a few other resources that can help you.
Clean Code by Robert C. Martin
As suggested by AllanC on a previous post, Clean Code is a book written to help you improve your coding habits. It covers a wide range of topics (such as meaningful names, pertinence of comments, code formatting, etc). Martin gives in-depth explanation for every point that he makes and includes real world examples. I haven’t read the book myself (it’s on my todo list!), but I’ve heard that it’s a difficult read. Some experience with Java is needed to fully appreciate the examples given. This book will definitely change your viewpoint on programming and what it means to have “clean code”. You can find the book on Amazon. Also, here’s a table of contents and (if you scroll down to the comments) a few reviews of the book.
Wikipedia: Programming style
Wikipedia’s article on programming style has all sorts of information on coding habits and styles. It focuses on the appearance of the code more so than the logic behind the code. It covers a large amount of practices, such as the use of whitespace and indenting. The great part of this resource is that the page links out to many other pages that are focused on more specific topics. The information on Wikipedia on programming style is not limited to just this article – it includes much, much more.
Zend Framework’s Coding Standards
The reference guide of the Zend Framework includes a whole section dedicated to coding standards and style. You don’t have to follow the coding standards there strictly unless you are contributing code to the project, but you can still read the recommendations that are made and learn from them. Everything is covered in this in-depth guide. The guide also includes PHP examples, which is great if you are working with PHP.
CodeIgniter’s Style Guide
CodeIgniter’s style guide is similar in purpose to the Zend Framework reference. It provides people guidelines to use when submitting code to the open source project. As with the Zend Framework guide, you can still follow the coding standards even if you aren’t contributing to the project. This guide is helpful in that it gives examples of what doesn’t follow the coding standards as well as what does.
Drupal’s Coding Standards
There’s not much to say about Drupal’s coding standards that hasn’t been already said. This guide isn’t as in-depth as the previous but it still provides standards that can be followed.
Basically, the best way to utilize these resources is to look through them until you find standards that you like. You can then learn the standards and perfect them. The most important thing is that you are consistent. If you start off a project planning to follow specific standards, you should continue following those standards throughout the project.
But what if you would rather develop your own set of standards instead of following the standards created by others? I’ll be doing a post on this in the near future – stay tuned.