Skip to content
Jim Posen edited this page Aug 18, 2013 · 10 revisions

To stay consistent with the style of this project, please abide by the following guidelines. If your code does not follow style guidelines, you should leave a comment explaining why. For all languages, the following rules apply:

  • Use spaces instead of tabs
  • Use Pokemon references liberally when writing tests. Only the first 151 Pokemon are recognized.

Annotations

This section is taken from the CoffeeScript style guide, but it's important enough to copy here.

Use annotations when necessary to describe a specific action that must be taken against the indicated block of code. Write the annotation on the line immediately above the code that the annotation is describing. The annotation keyword should be followed by a colon and a space, and a descriptive note.

  # FIXME: The client's current state should *not* affect payload processing.
  resetClientState()
  processPayload()

If multiple lines are required by the description, indent subsequent lines with two spaces:

  # TODO: Ensure that the value returned by this call falls within a certain
  #   range, or throw an exception.
  analyze()

Annotation types:

  • TODO: describe missing functionality that should be added at a later date
  • FIXME: describe broken code that must be fixed
  • OPTIMIZE: describe code that is inefficient and may become a bottleneck
  • HAX: describe the use of a questionable (or ingenious) coding practice
  • REVIEW: describe code that should be reviewed to confirm implementation

Ruby

Generally abide by these style guidelines, with the following exceptions/additions:

  • Use Ruby 1.9 syntax for hashes and lambdas
# bad
{ :a => 1, 'b' => 2 }
lambda { |x, y| x + y }

# good
{ a: 1, 'b' => 2 }
->(x, y) { x + y }
# bad
x.nil? || x.length == 0
!(x.nil? || x.length == 0)

# good
x.blank?
x.present?
  • Keep require statements in alphabetical order

CoffeeScript

All client side scripts should be written in CoffeeScript, NOT JavaScript. Generally abide by these style guidelines, with the following exceptions/additions:

  • When calling methods on this do not use @
# bad
@doStuff()
this.instanceVariable = 5

# good
this.doStuff()
@instanceVariable = 5
  • Make use of the Underscore library for utility functions
  • Prefer wrapping function arguments in parenthesis unless the last argument is a callback. This is a loose guideline.
# bad
pikachu.attack target, 'thunderbolt'
pikachu.attack(target, 'thunderbolt', ->
  this.evolveInto('Riachu')
)

# good
pikachu.attack(target, 'thunderbolt')
pikachu.attack target, 'thunderbolt', ->
  this.evolveInto('Riachu')
Clone this wiki locally