Ruby On Rails coding conventions, standards and best practices
-
Upload
david-paluy -
Category
Self Improvement
-
view
4.945 -
download
9
description
Transcript of Ruby On Rails coding conventions, standards and best practices
Ruby On Rails coding conventions, standards
and best practices
David PaluyAugust 2012
Philosophy (from Rails)
● DRY – Don't Repeat Yourself
● Convention over Configuration
● YAGNI - You ain't gonna need it
Source code Style
● Two spaces, no tabs● Boolean tests:
don't use “and” and “or”, always use “&&” and “| |”
Go Easy on the Comments
● If it's obvious – don't explain it● Remove old commented code● “How to” comments
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
Parentheses (Optional)
Parentheses (Do & Don't)
Folding Up Lines
Folding Up Blocks
if vs unless
while vs until
Use Modifier Forms
each, NOT for
In the Wild
Use Symbols to Stand for Something
Composing Methods for Humans
Make the code a little more articulate
Readable Code
Readable code makes your classes easier to test
Git
the diff says what you did;
your commit message should tell me why you did this
Summary
Good code is like a good joke:
It needs no explanation
Credentials