Skip to content

Latest commit

 

History

History
30 lines (21 loc) · 1.42 KB

Writing Quality Code.md

File metadata and controls

30 lines (21 loc) · 1.42 KB

We strive to write code that conforms to the 4 rules for developers by Sandi Metz:

  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 should only know about one instance variable.

Please read an article on those 4 rules.

The 4th rule can be a handful to conform to. Whenever in doubt of breaking any rule generally, follow this:

  1. Don't violate a guideline without a good reason.
  2. A reason is good when you can convince a teammate.

Since it's often a handful, just note that the reason it's created is because of controller actions like this one.

Other guidelines

  • Avoid writing class methods - they resist refactoring and are better as extracted objects with one public method and multiple privates then as a single class method. Class methods should only be used for describing a rule that's applied for all instances:
class Order
  def self.policy_class
    OrderPolicy
  end
end
  • Avoid writing local variables - most local variables are better off as extracted methods.