Prince:Ruby Best Practices

From OpenWetWare
Revision as of 09:07, 24 May 2011 by John T. Prince (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Home        Lab Members         Research         Publications         Internal         Mass Spec         Contact        


[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