Ruby On Rails coding conventions, standards and best practices

22
Ruby On Rails coding conventions, standards and best practices David Paluy August 2012

TAGS:

description

 

Transcript of Ruby On Rails coding conventions, standards and best practices

Page 1: Ruby On Rails coding conventions, standards and best practices

Ruby On Rails coding conventions, standards

and best practices

David PaluyAugust 2012

Page 2: Ruby On Rails coding conventions, standards and best practices

Philosophy (from Rails)

● DRY – Don't Repeat Yourself

● Convention over Configuration

● YAGNI - You ain't gonna need it

Page 3: Ruby On Rails coding conventions, standards and best practices

Source code Style

● Two spaces, no tabs● Boolean tests:

don't use “and” and “or”, always use “&&” and “| |”

Page 4: Ruby On Rails coding conventions, standards and best practices

Go Easy on the Comments

● If it's obvious – don't explain it● Remove old commented code● “How to” comments

Page 5: Ruby On Rails coding conventions, standards and best practices

Camels for Classes, Snakes Everywhere Else

● “Snake case”: lowercasse_words_separated_by_underscore

● “Camel case”: ClassName goodClass_name bad

● Constants: (my own preference)ALL_UPPERCASE = true

Page 6: Ruby On Rails coding conventions, standards and best practices

Parentheses (Optional)

Page 7: Ruby On Rails coding conventions, standards and best practices

Parentheses (Do & Don't)

Page 8: Ruby On Rails coding conventions, standards and best practices

Folding Up Lines

Page 9: Ruby On Rails coding conventions, standards and best practices

Folding Up Blocks

Page 10: Ruby On Rails coding conventions, standards and best practices

if vs unless

Page 11: Ruby On Rails coding conventions, standards and best practices

while vs until

Page 12: Ruby On Rails coding conventions, standards and best practices

Use Modifier Forms

Page 13: Ruby On Rails coding conventions, standards and best practices

each, NOT for

Page 14: Ruby On Rails coding conventions, standards and best practices

In the Wild

Page 15: Ruby On Rails coding conventions, standards and best practices

Use Symbols to Stand for Something

Page 16: Ruby On Rails coding conventions, standards and best practices

Composing Methods for Humans

Page 17: Ruby On Rails coding conventions, standards and best practices

Make the code a little more articulate

Page 18: Ruby On Rails coding conventions, standards and best practices

Readable Code

Page 19: Ruby On Rails coding conventions, standards and best practices

Readable code makes your classes easier to test

Page 20: Ruby On Rails coding conventions, standards and best practices

Git

the diff says what you did;

your commit message should tell me why you did this

Page 21: Ruby On Rails coding conventions, standards and best practices

Summary

Good code is like a good joke:

It needs no explanation

Page 22: Ruby On Rails coding conventions, standards and best practices

Credentials