ContributingGuidelines

Coding Standards

Coding Standards

When contributing code, you must follow the coding standards. To make a long story short, here is the golden rule: Imitate the existing project code.

Remember that the main advantage of standards is that every piece of code looks and feels familiar, it’s not about this or that being more readable.

General

  • These are not to be blindly followed; strive to understand these and ask when in doubt;
  • Don’t duplicate the functionality of a built-in library;
  • Don’t swallow exceptions or “fail silently”;
  • Don’t write code that guesses at future functionality;
  • Exceptions should be exceptional
  • Keep the code simple
  • Don’t create new anonymous functions in a loop;

Object-Oriented Design

  • Prefer private over protected, unless the class is meant to be extended;
  • A class with a fixed functionality should be marked final;
  • Avoid long parameter lists;
  • Limit collaborators of an object (entities an object depends on);
  • Limit an object’s dependencies (entities that depend on an object);
  • Prefer composition over inheritance;
  • Prefer small methods. Between one and five lines is best;
  • Prefer small classes with a single, well-defined responsibility. When a class exceeds 100 lines, it may be doing too many things;
  • Prefer immutable classes over mutable classes;
  • Tell, don’t ask

Browsers

  • Don’t support clients without Javascript;
  • Don’t support anything lower then IE9;

Language/framework specific guidelines