Skip to content

simpledream

Craftsmanship and Coding Standards

Inconsistencies [in your coding style] are jarring and require more time to read and comprehend. Consistency is such a valued quality that developers often abide by a coding standard even if they dislike the coding standard itself. —Chris Shiflett and Sean Coates

I consider following a coding standard a sure sign of a craftmanship. A craftsman knows his tools and languages well, and is consistent in his coding style. Ego and personal preference give way to consistency and best practices.

If you develop on your own, create a coding style and stick with it. There are many practical reasons to abide by code standards when developing on your own. It enforces good habits and helps avoid simple syntax bugs. It speeds up your development process by giving you structure and taking the guesswork out of naming and spacing tasks. And, possibly most importantly, it ensures your code is readable to your future self.

This is all fine and dandy when you’re the only one touching the code. When you share and collaborate with other developers, however, following a coding standard is not a choice—it is mandatory. If you develop for a platform, use the coding standards of the platform. Even if you don’t agree with the standard, you should follow it anyway so that your code is understandable and usable for other developers. Chances are the standards were put in place for very good reasons, both practical and philosophical.

To learn the coding standards for a project you work with, start by looking at other people’s code. Put the standards into practice in your own code and don’t be afraid to ask for a review from someone else. Check your code against similar structures in your software’s codebase, or popular modules, themes, and plugins for the software.

A big part of my job as Theme Wrangler at Automattic is reviewing themes. Lots of themes from lots of designers and developers. Everyone seems to have their own coding style, which makes it difficult to review code and find errors quickly. As a result I spend a lot of time cleaning up themes to match WordPress coding standards before I can even begin the actual work of reviewing and updating the theme.

For that reason code style consistency is especially important to me. It enforces best practices, produces consistent code, and speeds up development between collaborators.

Examples

For the languages I code in often (PHP, HTML, CSS, JavaScript), I use the same general set of standards.

  • Use standard syntax.
  • Remove extra whitespace and line endings.
  • Use consistent spacing and indentation.
  • Use human-readable labels and names.

Following are examples of specific coding standards that I follow in my everyday development.

For a top-notch example of coding standards within a company, see the Fellowship Technologies Code Standards. That, friends, is a well-crafted coding standard that we can all learn from.

Top 10 Lists vs. Web Craftsmanship

Are you the type of person who loves to read Top 10 lists, and then link them up on Twitter ad nauseam? Do you love Smashing Magazine and the tuts+ network (psdtuts, nettuts, …)? If so, this post is for you.

My latest pet peeve involves people who post and share links to web design and development tricks and “quick hit” tutorials. What are the odds that the list or tutorial is going to help you with your current work? Also, did you actually go read the list and follow the links and do the tutorial and launch a site based on it and can you show that product to me? What did you actually learn?

The tendency toward listmania is misleading at best and damaging to the web design and development community at worst. It promotes superficial knowledge, quick fix schemes, and small-minded solutions.

If you want to do quality work and be proud of your craft, avoid these sites and lists. The quick trick can’t make you a better web craftsman or -woman. There isn’t a shortcut or quick fix to learning web design and development fundamentals.

Instead spend time actually making awesome sites yourself. Build something and launch it to the public. Go to An Event Apart. Learn by doing: your experience will teach you more than any top 10 list ever will. The critical thinking and solid skills will come from your hard work, not from the latest, hottest tut.1

More fuel for the fire:

Here is the thing. While it’s fun to learn the latest way to vertically center a div on a page using jQuery, HTML5 and your mom, you’re wasting your time. You may use that what, 1-2% of the time in your projects. Your fundamentals are what is important. Positioning, layouts, typography, spacing, etc. Master those things. Tricks are just tricks. Fundamentals win the game. —Noah Stokes

One can only really learn by doing, by making mistakes, and not by following someone else’s abridged instructions. The tips might get you a quick ‘n’ dirty result, but after that, you’re none the wiser and will need more hints to get you through the next problem. To anyone with genuine aspirations to be great and to really improve themselves, drop the ridiculous lists of quick fixes and shortcuts and start learning for yourself by doing and by making mistakes. —Contrast blog

There is a “quick hit” culture amongst net junkies, where they read the bare minimum and foolishly believe they’re getting value or insight. These are the same people who bookmark links “to read later” but never do, and order piles of amazon books to sit on shelves forever. Someone thinking they’re getting value of 10 sentences along the lines of “Launch early, launch often” or “Your brand is beyond your control” is in need of far more than a top 10 list in my opinion. —commenter on the same Contrast post

1 And, this is silly, but I hate the word “tut” so much. Argh!