ruby on rails coding conventions, standards and best practices
DESCRIPTION
TRANSCRIPT
![Page 1: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/1.jpg)
Ruby On Rails coding conventions, standards
and best practices
David PaluyAugust 2012
![Page 2: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/2.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/3.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/4.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/5.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/6.jpg)
Parentheses (Optional)
![Page 7: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/7.jpg)
Parentheses (Do & Don't)
![Page 8: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/8.jpg)
Folding Up Lines
![Page 9: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/9.jpg)
Folding Up Blocks
![Page 10: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/10.jpg)
if vs unless
![Page 11: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/11.jpg)
while vs until
![Page 12: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/12.jpg)
Use Modifier Forms
![Page 13: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/13.jpg)
each, NOT for
![Page 14: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/14.jpg)
In the Wild
![Page 15: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/15.jpg)
Use Symbols to Stand for Something
![Page 16: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/16.jpg)
Composing Methods for Humans
![Page 17: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/17.jpg)
Make the code a little more articulate
![Page 18: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/18.jpg)
Readable Code
![Page 19: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/19.jpg)
Readable code makes your classes easier to test
![Page 20: Ruby On Rails coding conventions, standards and best practices](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/20.jpg)
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](https://reader034.vdocuments.mx/reader034/viewer/2022042513/53fc46c28d7f72384b8b4587/html5/thumbnails/21.jpg)
Summary
Good code is like a good joke:
It needs no explanation