Skip to content

Instantly share code, notes, and snippets.

// primitive types
var i = 3;
var f = 3.14;
var s = "hello" + " world";
var b = i < 5;
var n = null;
console.log(i, f, s, b, n);
// object types

###Sandi Metz's Rules For Developers

Sandi Metz states four rules to maintain good code:

  1. Classes can be no longer than one hundred lines of code.
  2. Methods can be no longer than five lines of code.
  3. Pass no more than four parameters into a method. Hash options are parameters.
  4. Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object.

I have struggled to write methods no longer that 5 lines and also send just one controller to the view. Creating short methods can be done by breaking logic out into descriptive private methods. I can see how this can also be abused to write methods improperly and just keep breaking the logic into other methods when some of the solution is to use better logic.