12 Principles For Keeping Your Code Clean

Smashing Magazine is a site I vist almost on a daily basis. They have great articles on writing code, using CSS as well as resources for lots of F REE stuff. Today’s article is 12 Principles For Keeping Your Code Clean by Chris Coyier.

Beautiful HTML is the foundation of a beautiful website. When I teach people about CSS, I always begin by telling them that good CSS can only exist with equally good HTML markup. A house is only as strong as its foundation, right? The advantages of clean, semantic HTML are many, yet so many websites suffer from poorly written markup.

Let’s take a look at some poorly written HTML, discuss its problems, and then whip it into shape! Bear in mind, we are not passing any judgment on the content or design of this page, only the markup that builds it.

He includes the following with good examples and explanations:

  1. Strict DOCTYPE – while I practice this (using the strict doctype) I do not recommend it for everyone.
  2. Character set & encoding characters – not using the code for the ampersand will quite often cause validations problems
  3. Proper indentation – has no bearing on how the page is rendered, but it has a huge effect on the readability of the code.
  4. Keep your CSS and JavaScript external – Keeping your CSS files as external files rather than in the head section means that future pages can link to the sheets and use the same code
  5. Nest your tags properly
  6. Eliminate unnecessary divs
  7. Use better naming conventions – rather than a class called bigredtext perhaps important would be more appropriate
  8. Leave typography to the CSS –
  9. Class/id the <body>
  10. Validate
  11. Logical ordering
  12. Just do what you can

You can read 12 Principles For Keeping Your Code Clean on the Smashing Magazine website. At the same time, you might want to sign up for their RSS feed.

Speak Your Mind

*