Coding conventions

Identation

The indentation is 2 spaces, for all the following languages.

Ruby

General

Avoid using return in methods.

Use
def method
  value
end
   
instead of
def method
 return value
end
   

Access instance's methods using self.

The use self.method_name instead of just method_name make clear that an instance thing, not a variable, is being used.

Also, for setters, some times ommitting the self. will lead to a bug as it will create a variable instead of calling the instance method.

When a method has arguments, always use parenthesis in its declaration

Models

  1. relationships (has_many, belongs_to, etc) and applied behaviour (acts_as_*)
  2. virtual attributes, if needed
  3. validations
  4. business logic in general

Thin controllers, fat models

  • every time you write a method with more than, say, 5 lines in a controller, consider if some of its logic shouldn't go inside a model class
  • NEVER reference anything but assigned @variables inside templates (.rhtml)

Testing

  • test every validation that you add to ActiveRecord models
  • add a test to your unit tests that passes all your fixtures through ActiveRecord validation, unless you are using an individual fixture as invalid data on purpose. Name your invalid data fixtures with "invalid_" as prefix.
  • every model must have unit tests
  • every controller must have functional tests. At least one test for each action.
  • every user story must have one or more corresponding integration tests.
  • Rcov reports must present 100% coverage of everything

Special Conventions

Javascript

CSS


Add comment
You need to login to be able to comment.
 
Topic revision: r10 - 07 Oct 2013 - 14:19:39 - BraulioBhavamitraBO
Anhetegua.CodingConventions moved from Multypass.CodingConventions on 11 Jul 2007 - 18:48 by AntonioTerceiro

irc Talk with Devs Now!

 
Translations: English, Português
Search on Docs:
   
ActionItem Search:

Copyright © 2007-2014 by the Noosfero contributors
Colivre - Cooperativa de Tecnologias Livres