Coding Conventions
and
Best Practices
What's the big deal?
WARNING
Some points may be highly controversial
Please don't debate with me, it's just my little ol' opinion
camelCase

Naming Convetions
"I have no idea what this does"
function k(c, y){
return c * y;
}function weeklyPay(hoursWorked, payRate){
return hoursWorked * payRate;
}Capitalizing Models


POST/GET/PUT/DELETE
-
Just verbs, but not just verbs
-
Abstraction
Reusability
angular.module('Store', [])
.controller('OrderCtrl', function ($scope) {
$scope.items = [];
$scope.addToOrder = function (item) {
$scope.items.push(item);
};
$scope.removeFromOrder = function (item) {
$scope.items.splice($scope.items.indexOf(item), 1);
};
$scope.totalPrice = function () {
return $scope.items.reduce(function (memo, item) {
return memo + (item.qty * item.price);
}, 0);
};
});Good
angular.module('Store', [])
.controller('OrderCtrl', function (Order) {
$scope.items = Order.items;
$scope.addToOrder = function (item) {
Order.addToOrder(item);
};
$scope.removeFromOrder = function (item) {
Order.removeFromOrder(item);
};
$scope.totalPrice = function () {
return Order.total();
};
});angular.factory('Order', function(){
return {
addToOrder: function(item){
this.items.push(item);
},
removeFromOrder: function(item){
this.items.splice(this.items.indexOf(item), 1)
},
totalPrice: function(){
return this.items.reduce(function (memo, item) {
return memo + (item.qty * item.price);
}, 0);
},
items: []
}
})Reusability
keep logic in factories
-
keep routes clean
-
logic in the models

-
Don't confuse yourself for no reason
-
Consider others
- readable
- modular
- abstracted
- re-usable
Style guide sources
- Node: https://github.com/felixge/node-style-guide
- Angular: https://github.com/mgechev/angularjs-style-guide
Coding Conventions
By Joanne Yae
Coding Conventions
- 233