Skip to content

Instantly share code, notes, and snippets.

@stevepentler
Last active March 15, 2016 17:38
Show Gist options
  • Save stevepentler/fdfa3b6f433be074b0f6 to your computer and use it in GitHub Desktop.
Save stevepentler/fdfa3b6f433be074b0f6 to your computer and use it in GitHub Desktop.
Sandi Metz' Rules For Developers

#####Classes can be no longer than one hundred lines of code. #####Methods can be no longer than five lines of code. #####Pass no more than four parameters into a method. Hash options are parameters. #####Controllers can instantiate only one object. Therefore, views can only know about one instance variable.

In my opinion, the 5 line limit is the most difficult to follow. I think the key to adhering to the rule is overly-descriptive method naming so anyone reviewing your code can easily distinguish what is happening within the method.

I've been using presenters lately, and I think it really helps move logic down the stack. Especially when you want to generate random offsets or have minimal amounts of logic, it's nice to be able to stick it in a PORO away from the controllers. In addition, the super method you get from SimpleDelegator is extremely helpful when passing a service just for its methods.

Class limitations can be the hardest to practice, but are the most easily solved with modules.

I don't think I've ever tried to pass 4 parameters in a method.

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