Skip to content

Instantly share code, notes, and snippets.

@Jpease1020
Last active March 20, 2016 23:46
Show Gist options
  • Save Jpease1020/81612cafc187549e5437 to your computer and use it in GitHub Desktop.
Save Jpease1020/81612cafc187549e5437 to your computer and use it in GitHub Desktop.

###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.

I would have liked to take more advantage of learning how to send over just one object to the view in mod 3. There are some great tips here on how to do that and I just never really tackled that in mod 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment