Skip to content

Coding Standards

Mark Healey edited this page Aug 30, 2013 · 3 revisions

Separate from this document, we have guidelines for contributing; please familiarize yourself with them before making changes to F2 and sending pull requests.

Coding standards promote a common vocabulary and syntax so that our fellow developers can concentrate on what you're saying rather than on how you're saying it. It is ultimately up to you how you write your own code, but please become familiar with the standards and use them when contributing back to the F2 project on GitHub.

Coding standards help an individual project, and also make it easier for one project to reuse components from another project. This, of course, is a core component of F2.

If you have any questions while writing code to contribute back to F2, drop us a note on our Google Group, on Twitter @OpenF2 or by email at [email protected].

HTML/CSS Style Guide

Google has done a tremendous job presenting a style guide we all can adopt (with some exceptions). CSS written for F2 should follow Google's HTML/CSS Style Guide documentation, except the following:

  • Google recommends 2 spaces, we enforce tabs equivalent to 4 spaces.
  • While HTML5 does define closing tags as optional for a number of elements, we will continue to close all tags.
  • It is perfectly acceptable to use actual characters in lieu of HTML character entities so long as the data source, text editor and file format are using UTF-8.

JavaScript Style Guide

Like their HTML/CSS guide, Google's JavaScript Style Guide is excellent. There are a couple of minor exceptions:

  • For jQuery, we name all jQuery variables with a leading $. This notation informs developers that a variable is a jQuery object.
  • Tab indention should be used instead of spaces.
  • Leading underscores (_) should be used to indicate private or protected methods. (Google calls for trailing underscores).

Tabs vs. Spaces

This one is easy and deserves its own call-out: tabs! Your F2 code should be indented with tabs.

Clone this wiki locally