Writing quality code

We strive to write code that conforms to the four 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 these four rules.

You may find it difficult to conform to the fourth rule. In general, whenever you think you might be breaking a rule, 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 difficult, just remember that it was created because of controller actions like this one.

Other guidelines

class Order
  def self.policy_class