Skip to content

Instantly share code, notes, and snippets.

@GregoryArmstrong
Created March 17, 2016 17:02
Show Gist options
  • Save GregoryArmstrong/8249edaf6d071ebe3bb2 to your computer and use it in GitHub Desktop.
Save GregoryArmstrong/8249edaf6d071ebe3bb2 to your computer and use it in GitHub Desktop.
Sandi Metz' Rules For Developers
  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.

For me the most difficult to follow would be rule #4. In my last few modules Ive tried to adhere to SRP for methods and classes and that seems to bring down the line length for such things on its own. I am usually only using 1 or 2 arguments for a method anyways, so 3 isnt too difficult either. But #4 is problematic as Ive begun to use POROs more frequently, and so ive gotten used to using 2 or 3 in a controller. It will definitely force me to adhere even more to SRP, but sometimes I feel it's useful to have a couple of instantiated objects. I'll try it on my next project as a challenge to myself.

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