Skip to content

Commit

Permalink
1 liner up top is ok. closes #27
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpapa committed Aug 11, 2014
1 parent bd024ec commit 6bcf6d0
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,41 @@ Many of my styles have been from the many pair programming sessions [Ward Bell](
}
```
- Note: If the function is a 1 liner it consider keeping it right up top, as long as readability is not affected.
```javascript
/* avoid */
function Sessions(data) {
var vm = this;

vm.gotoSession = gotoSession;
vm.refresh = function() {
/**
* lines
* of
* code
* affects
* readability
*/
};
vm.search = search;
vm.sessions = [];
vm.title = 'Sessions';
```
```javascript
/* recommended */
function Sessions(data) {
var vm = this;

vm.gotoSession = gotoSession;
vm.refresh = function() {data.refresh();}; // 1 liner is OK

This comment has been minimized.

Copy link
@vbrajon

vbrajon Aug 11, 2014

Why don't you use short syntax here ?

vm.refresh = data.refresh;

This comment has been minimized.

Copy link
@Siyfion

Siyfion Aug 11, 2014

Contributor

Because data.refresh is a function, not a value? ie. Imagine it's a service that gets updated data from a server.

This comment has been minimized.

Copy link
@johnpapa

johnpapa Aug 11, 2014

Author Owner

actually, that's what I mean to write. I'll amend that.

vm.search = search;
vm.sessions = [];
vm.title = 'Sessions';
```
- **Defer Controller Logic**: Defer logic in a controller by delegating to services and factories.
*Why?*: Logic may be reused by multiple controllers when placed within a service and exposed via a function.
Expand Down Expand Up @@ -483,7 +518,6 @@ Many of my styles have been from the many pair programming sessions [Ward Bell](
*Why?*: Setting functions as you go can be easy, but when those functions are more than 1 line of code they can reduce the readability and cause more scrolling. Defining the callable interface via the returned service moves the implementation details down, keeps the callable interface up top, and makes it easier to read.
```javascript
/* avoid */
function dataService () {
Expand Down

0 comments on commit 6bcf6d0

Please sign in to comment.