Coding Guidelines
- Every design choice should yield the most simplistic design possible for the need of users at the current time. No guesses for future functionality were designed into the application.
- There is zero custom code that duplicates functionality of a built-in function in the framework
- Every fixed defect on a deployed product has tests added to prevent regression.
- All tests pass before code is merged into a shared repository.
- All model and variable names are both immediately obvious (to a new developer) and as short as possible without using abbreviations
- Only one or two instance variables are shared between each controller and view
- Code has been aggressively DRYed during development.
- No .find or similar methods are called in a view or view helper
- Methods must not be longer than 10 lines of code. Shouldn’t be more than 5 lines of code
- Try to avoid if and never use nested if/unless. Think of unless as in “return unless goon?” nested code gets more unreadable
- Never use Copy&Paste
- Always read what you’ve written and rethink it
- Always ask: “Does it feel right?” “Do I understand this 6 months from now?”
- A method must always return the same kind of object
- When using a method allways ask what that method returns and use appropriately.
- When writing documentation or any kind of comments always write about “WHY?” (not about “how?”)
- If you do anything twice think about how you can prevent that but stay pragmatic!
- Read the logs! What SQLs do you fire? Use newrelic in development mode and analyze your requests
- If you’re not using form_for for updating your models, you’re probably doing it wrong