I've found some recurring issues that arise relating to code quality, so have set out to write a mini-code standard.
- IN ESSENCE: ALL CODE SHOULD BE READABLE!
- DO NOT OPTIMISE for performance - OPTIMISE FOR CLARITY OF CODE
- STYLE: use 2 spaces for indent (not tabs)
- STYLE: Line up hash arrows for readability
- STYLE: put spaces around => hash arrows
- STYLE: put spaces after ',' in method params - but none between method names and '('
- VIEWS: use HAML for views
- VIEWS: break up the structure with white space to help readability - VERTICALLY TOO!
- VIEWS STYLE: Rely on structure of page, without having to insert messages or new components...
- Example: Effect to visually highlight then drop out an existing element rather than flash a message
- Example: Highlight newly added row rather than a message about it
- AVOID logic in views - they should be simple
- put html generating logic into helpers
- instead of inline ruby logic, add to models (filtering, checking)
- NEVER use ActiveRecord models in migrations unless you re-define them within the migration
- ...otherwise the migration fails when you later remove/rename the AR class
- BETTER SOLUTION: use bootstrapping until deployed!!!
- AJAX only for sub-components of an object, and avoid over-use
Now the problem with code standards, is that they need to be adhered to, or they're totally useless. That's why the above is very short and easy to comprehend in one quick sitting.
What would you add or remove?