-
Notifications
You must be signed in to change notification settings - Fork 6
Style Guide
Courtesy of Rob Yang
Coding Style Guidelines
Expectations:
We all have varied styles of coding with strengths and weaknesses in the myriad aspects of OOD. With that said, it is going to be a painful few days of adjustment and constant reminders to each other to be disciplined in meeting a unified standard.
Goals:
To reach for coding excellence. To easily connect our pieces together. To instantly know what a class and/or method does simply by its name.
Standard Operating Procedure:
Failure to adhere to these rules will result in a rejected pull request. The rejected pull request will point out the specific “code smell”, possibly with a suggested alternative. Alternatives may not always be provided, as sometimes things just smell fishy. If a “code smell” is deemed as non-critical, then it will be noted in the comments that refactoring is needed, in the future.
Style conventions / best practice:
JavaScript:
Use the object literal notation for prototyping methods. See Steven Harm’s code in Appendix. Declare a new namespace. methodsWillBeCamelCased(); ClassNameCapitalized(); Use informative comments - what is the point of the code you just wrote? TL;DR
OOP principles / syntax:
Rails:
Never reference a model name inside your view file. Use the controller to send the model’s info to the view. No data manipulation in view. Never put logic or computation about a model in the controller. Example: if you want to know the average of ratings, make a method inside the Rating model. Finding out interesting information about an object should be the object’s duty. Your controller should only reference a model name in the following circumstances: Reading from the DB. Writing to the DB. Updating the DB. Deleting data in the DB. Unless you have a model that does a task (daygreeter) Ruby: Never reference another class name inside a method of another class. Never metaprogram.
JavaScript:
Always declare variables using “var”. Always declare a namespace. Use classes with prototyped methods. No functions floating out in space, please. Keep your methods to single responsibility. If you have a loop inside your method, see if you can break it apart even further.
Appendix
JavaScript Grocery List:
https://github.com/ospreys-2014/behavior-drill-grocery-list-challenge/blob/steven-implementation/source/grocery-controller.js https://github.com/ospreys-2014/behavior-drill-grocery-list-challenge/blob/steven-implementation/source/grocery-item.js