Prince:Ruby Best Practices: Difference between revisions
From OpenWetWare
Jump to navigationJump to search
(New page: {{PrinceLab}} [From Russ Olsen's Eloquent Ruby] The ruby community has settled on some conventions in an effort to create readable code. Following these conventions will help you to writ...) |
(No difference)
|
Revision as of 09:07, 24 May 2011
[From Russ Olsen's Eloquent Ruby] The ruby community has settled on some conventions in an effort to create readable code. Following these conventions will help you to write clean code and allow others to understand it.
Chapter 1
- readability/comprehensibility trumps all other conventions
- Indent with 2 spaces (use spaces over tabs)
- CamelCase classes, snake_case_everything_else, & CONSTANTS_UPPER_SNAKE
- generally use parentheses for arguments (can sometimes leave off): mymethod(one, 3)
- leave parentheses off empty argument lists: word.split
- generally leave parentheses off control statements, so write: if something...
- one line block: {}, multi-line block: do ...\n... end
Chapter 2
- if/unless & while/until are logical pairs: use the one that fits the occasion
- use each instead of for