This repository was archived by the owner on Oct 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Coding Conventions
Pascal Reinhardt edited this page Nov 22, 2013
·
8 revisions
- no abbreviations in names
- camelCase for Classes and Modules, snake_case for variables and methods, SKREAMING_SNAKE_CASE for constants
- hyphen-case for css classes and ids
- use ! suffix for dangerous methods (modify self, exception)
- use ? suffix for boolean returning methods
- use implicit return only for single liners
- avoid superfluous parentheses
- use parentheses when defining methods with parameters
- don’t use unless with else
- use unless instead of if not
- use || and && for boolean expressions
- use ‘and’ or ‘or’ to connect statements
- use single line statements if possible
- use ||= and a = b or c
- use {} for single line blocks
- use ‘ for strings in ruby or js, “ for html
- def self.method for class methods
- use 2 spaces for indentation
- leave 1 space between operators
- leave 1 new line before classes and methods
- no useless comments
- heavy models, light controllers
- :only before :except, but whatever is shorter
- limit number of instance variables shared between controller & view
- order of model contents: constants, attributes, associations, nested attributes, named scopes, validations, callbacks, public methods, private methods
- annotate models after migrations