Choose a Github Issue.
Create a local feature branch off of master for development.
git checkout master
git pull
git checkout -b 123-feature-xyz
Do work in your feature branch and commit the changes.
git add -A
git status
git commit
Write a good commit message.
[#123] Summary of changes under 50 characters
* More information about commit (under 72 characters)
* More information about commit (under 72 characters)
A good commit message:
- Prefixes the subject line with a Github Issue number.
- Uses the present tense.
Share your feature branch
git push origin [branch]
Rebase frequently to incorporate upstream changes.
git checkout master
git pull
git checkout [branch]
git rebase master
<resolve conflicts>
Interactive rebase (squash) your commits (if necessary).
git rebase -i master
Merge your branch back to master and push your changes.
git checkout master
git diff --stat master [branch]
git merge [branch] --ff-only
git push origin master
Delete your remote feature branch.
git push origin :[branch]
Delete your local feature branch.
git branch -d [branch]
Close Github Issue.
- Aggressively DRY code during development.
- Avoid abbreviations.
- Avoid comments.
- Avoid global variables.
- Avoid long parameter lists.
- Be consistent.
- Delete trailing whitespace.
- Don't duplicate the functionality of a built-in library.
- Don't over-design.
- Don't program defensively.
- Don't use an empty line at the beginning or end of methods, blocks or conditionals.
- Don't vertically align tokens on consecutive lines.
- Don't write more code than you need.
- Exceptions should be exceptional. Don't suppress them or use them for control flow.
- Guesses at future functionality should not be designed into the application.
- Keep methods small.
- Keep the code simple.
- Limit lines to a maximum of 120 characters.
- Make sure all tests pass before code is merged into a shared repository.
- Name variables, methods, and classes with intention-revealing names..
- No spaces after
(,[. No spaces before],). - Order variables and methods alphabetically when possible.
- Prefer single function exit points unless the complexity of the code is greatly reduced by multiple returns.
- Treat acronyms as words in names (
XmlHttpRequestnotXMLHTTPRequest), even if the acronym is the entire name (class Htmlnotclass HTML). - Use 2 space indentation (no tabs) unless otherwise noted.
- Use an empty line between methods, blocks and conditionals.
- Use ASCII (or UTF-8, if you have to).
- Use default iterators for languages/types that support them.
- Use descriptive names that are both immediately obvious (to a new developer) and as short as possible without using abbreviations.
- Use implicit line joining where possible and indent continued lines.
- Use spaces around operators, after commas, colons and semicolons, around
{and before}. - Use standard language conventions for API documentation.
- Use Unix-style line endings (
\n).
- Avoid
%q,%Q,%x,%s, and%W. - Avoid conditional modifiers (lines that end with conditionals).
- Avoid hashes as optional parameters. Does the method do too much?
- Avoid including code and gems in source control that are specific to your
development machine or process. Examples:
.rvmrcs, file watchers, debuggers. - Avoid meta-programming.
- Avoid monkey-patching core classes.
- Avoid return unless required.
- Avoid superfluous parentheses when calling methods, but keep them when you assign the return value. x = Math.sin(y) array.delete e
- Avoid ternary operators (
boolean ? true : false). Use multi-lineifinstead to emphasize code branches. - Don't use
unlesswithelse. - Prefer
mapovercollectandreduceoverinjectdue to symmetry and familarity with mapping and reducing in other technologies. - Prefer
detectoverfindandfind_alloverselectto avoid confusion with ActiveRecord and keepselect/rejectsymmetry. - Use
_for unused block parameters. hash.map { |_, v| v + 1 } - Use
%()for single-line strings needing interpolation and double-quotes. - Use
%w()over['', '']for an array of words. - Use
&&and||for boolean expressions. - Use
||=freely. - Use
{...}overdo..endfor single-line blocks. - Use
!suffix for dangerous methods (modifiesself). - Use
?suffix for predicate methods (return a boolean). - Use
CamelCasefor classes and modules,snake_casefor variables and methods,SCREAMING_SNAKE_CASEfor constants. - Use
defwith parentheses when there are arguments. - Use
do..endover{...}for multi-line blocks. - Use heredocs for multi-line strings.
- Use
/(?:first|second)/over/(first|second)/when you don't need the captured group. - Use
privateoverprotectedto indicate scope. - Use
def self.methodoverdef Class.methodorclass << self. - Use
SetoverArrayfor arrays with unique elements. The lookup is faster. - Use single-quotes for strings unless variable interpolation is required.
- Use
unless boolean?instead ofif !boolean?. - Use Factory Girl for setting up complicated test data.
- Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
- Use a = b and not a=b.
- Aim for skinny models and skinny controllers.
- Avoid the
:exceptoption in routes. - Avoid
memberandcollectionroutes. - Avoid Single Table Inheritance.
- Consider extracting
privatemethods to their own object. - Don't invoke a model's class directly from a view.
- Don't use SQL or SQL fragments (
where('inviter_id is not null')) outside of models. - Set
config.action_mailer.raise_delivery_errors = truein the development environment. - Initialize code in
config/initializers. - Keep the
db/schema.rbunder version control. - Limit database defaults to counter caches and booleans.
- Limit the number of instance variables shared between controller and view.
- Name initializers for their gem name. Example:
paperclip.rb - Order controller contents: filters, public methods,
privatemethods. - Order model contents: constants, attributes, associations, nested attributes,
named scopes, validations, callbacks, public methods,
privatemethods. - Prefer classes to modules when designing functionality that is shared by multiple models.
- Prefer gems over plugins.
- Prefer presenters (Ruby objects responsible for presentation) over view helpers.
- Put all copy text in models, views, controllers, and mailers in
config/locales. - Set
config.action_mailer.delivery_method = :testin the test environment. - Use
_pathover_urlfor named routes everywhere except mailer views. - Use
def self.methodover thenamed_scope :methodDSL. - Use Foreman to run Rails apps in development mode.
- Use
I18n.t 'dot.separated.key'overI18n.t :key, :scope => [:dot, :separated]. - Use
has_and_belongs_to_manyif all you need is a join table. Start simple. - Use namespaced locale lookup in the views by prefixing a period:
t '.title'. - Use nested routes to express
belongs_torelationships between resources. - Use one
ActionMailerfor the app. Name itMailer. - Use single recipient SMTP in the staging environment.
- Use the default
render 'partial'syntax overrender :partial => 'partial'. - Use the
:onlyoption to explicitly state exposed routes.
- Avoid
its,specify,subject, and other DSLs. Prefer explicitness and consistency. - Disable real HTTP requests to external services.
- Don't prefix
itblocks with 'should'. - Prefix
contextblocks names with 'given' when receiving input. Prefix with 'when' in most other cases. - Name outer
describeblocks after the method under test. Useself.methodfor class methods andmethodfor instance methods. This matches the method definition itself. - Run specs with
--format documentation. - Stub requests to external services.
- Use a
contextblock for each execution path through the method. - Use
beforeblocks to clearly define the 'setup' phase of the Four Phase Test. - Use integration tests to execute the entire app.
- Use one expectation per
itblock. - Use stubs and spies (not mocks) to isolate unit tests as much as possible.