Skip to content

Commit 0ee19c3

Browse files
authored
Merge pull request #1 from ryanmcdermott/master
Bringing fork up to date
2 parents f727215 + 445af32 commit 0ee19c3

File tree

1 file changed

+40
-44
lines changed

1 file changed

+40
-44
lines changed

README.md

Lines changed: 40 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ setTimeout(blastOff, 86400000);
8888

8989
**Good:**
9090
```javascript
91-
// Declare them as capitalized `const` globals.
91+
// Declare them as capitalized named constants.
9292
const MILLISECONDS_IN_A_DAY = 86400000;
9393

9494
setTimeout(blastOff, MILLISECONDS_IN_A_DAY);
@@ -192,7 +192,7 @@ function createMicrobrewery(name) {
192192

193193
**Good:**
194194
```javascript
195-
function createMicrobrewery(breweryName = 'Hipster Brew Co.') {
195+
function createMicrobrewery(name = 'Hipster Brew Co.') {
196196
// ...
197197
}
198198

@@ -295,7 +295,7 @@ function addToDate(date, month) {
295295

296296
const date = new Date();
297297

298-
// It's hard to to tell from the function name what is added
298+
// It's hard to tell from the function name what is added
299299
addToDate(date, 1);
300300
```
301301

@@ -343,6 +343,14 @@ function parseBetterJSAlternative(code) {
343343

344344
**Good:**
345345
```javascript
346+
function parseBetterJSAlternative(code) {
347+
const tokens = tokenize(code);
348+
const ast = lexer(tokens);
349+
ast.forEach((node) => {
350+
// parse...
351+
});
352+
}
353+
346354
function tokenize(code) {
347355
const REGEXES = [
348356
// ...
@@ -367,14 +375,6 @@ function lexer(tokens) {
367375

368376
return ast;
369377
}
370-
371-
function parseBetterJSAlternative(code) {
372-
const tokens = tokenize(code);
373-
const ast = lexer(tokens);
374-
ast.forEach((node) => {
375-
// parse...
376-
});
377-
}
378378
```
379379
**[⬆ back to top](#table-of-contents)**
380380

@@ -440,22 +440,20 @@ function showEmployeeList(employees) {
440440
const expectedSalary = employee.calculateExpectedSalary();
441441
const experience = employee.getExperience();
442442

443-
let portfolio;
443+
const data = {
444+
expectedSalary,
445+
experience
446+
};
447+
444448
switch (employee.type) {
445449
case 'manager':
446-
portfolio = employee.getMBAProjects();
450+
data.portfolio = employee.getMBAProjects();
447451
break;
448452
case 'developer':
449-
portfolio = employee.getGithubLink();
453+
data.githubLink = employee.getGithubLink();
450454
break;
451455
}
452456

453-
const data = {
454-
expectedSalary,
455-
experience,
456-
portfolio
457-
};
458-
459457
render(data);
460458
});
461459
}
@@ -623,7 +621,7 @@ const addItemToCart = (cart, item) => {
623621
**Good:**
624622
```javascript
625623
const addItemToCart = (cart, item) => {
626-
return [...cart, { item, date : Date.now() }];
624+
return [...cart, { item, date: Date.now() }];
627625
};
628626
```
629627

@@ -661,7 +659,7 @@ class SuperArray extends Array {
661659

662660
### Favor functional programming over imperative programming
663661
JavaScript isn't a functional language in the way that Haskell is, but it has
664-
a functional flavor to it. Functional languages are cleaner and easier to test.
662+
a functional flavor to it. Functional languages can be cleaner and easier to test.
665663
Favor this style of programming when you can.
666664

667665
**Bad:**
@@ -707,11 +705,9 @@ const programmerOutput = [
707705
}
708706
];
709707

710-
const INITIAL_VALUE = 0;
711-
712708
const totalOutput = programmerOutput
713-
.map((programmer) => programmer.linesOfCode)
714-
.reduce((acc, linesOfCode) => acc + linesOfCode, INITIAL_VALUE);
709+
.map(output => output.linesOfCode)
710+
.reduce((totalLines, lines) => totalLines + lines);
715711
```
716712
**[⬆ back to top](#table-of-contents)**
717713

@@ -843,7 +839,7 @@ function travelToTexas(vehicle) {
843839
**[⬆ back to top](#table-of-contents)**
844840

845841
### Avoid type-checking (part 2)
846-
If you are working with basic primitive values like strings, integers, and arrays,
842+
If you are working with basic primitive values like strings and integers,
847843
and you can't use polymorphism but you still feel the need to type-check,
848844
you should consider using TypeScript. It is an excellent alternative to normal
849845
JavaScript, as it provides you with static typing on top of standard JavaScript
@@ -1114,10 +1110,10 @@ and you can chain further class methods onto it.
11141110
**Bad:**
11151111
```javascript
11161112
class Car {
1117-
constructor() {
1118-
this.make = 'Honda';
1119-
this.model = 'Accord';
1120-
this.color = 'white';
1113+
constructor(make, model, color) {
1114+
this.make = make;
1115+
this.model = model;
1116+
this.color = color;
11211117
}
11221118

11231119
setMake(make) {
@@ -1137,20 +1133,18 @@ class Car {
11371133
}
11381134
}
11391135

1140-
const car = new Car();
1136+
const car = new Car('Ford','F-150','red');
11411137
car.setColor('pink');
1142-
car.setMake('Ford');
1143-
car.setModel('F-150');
11441138
car.save();
11451139
```
11461140

11471141
**Good:**
11481142
```javascript
11491143
class Car {
1150-
constructor() {
1151-
this.make = 'Honda';
1152-
this.model = 'Accord';
1153-
this.color = 'white';
1144+
constructor(make, model, color) {
1145+
this.make = make;
1146+
this.model = model;
1147+
this.color = color;
11541148
}
11551149

11561150
setMake(make) {
@@ -1178,10 +1172,8 @@ class Car {
11781172
}
11791173
}
11801174

1181-
const car = new Car()
1175+
const car = new Car('Ford','F-150','red')
11821176
.setColor('pink')
1183-
.setMake('Ford')
1184-
.setModel('F-150')
11851177
.save();
11861178
```
11871179
**[⬆ back to top](#table-of-contents)**
@@ -1691,7 +1683,7 @@ you achieve very high confidence and developer peace of mind. This means that
16911683
in addition to having a great testing framework, you also need to use a
16921684
[good coverage tool](http://gotwarlost.github.io/istanbul/).
16931685

1694-
There's no excuse to not write tests. There's [plenty of good JS test frameworks](http://jstherightway.org/#testing-tools), so find one that your team prefers.
1686+
There's no excuse to not write tests. There are [plenty of good JS test frameworks](http://jstherightway.org/#testing-tools), so find one that your team prefers.
16951687
When you find one that works for your team, then aim to always write tests
16961688
for every new feature/module you introduce. If your preferred method is
16971689
Test Driven Development (TDD), that is great, but the main point is to just
@@ -1945,8 +1937,8 @@ class Alpaca {}
19451937
const DAYS_IN_WEEK = 7;
19461938
const DAYS_IN_MONTH = 30;
19471939

1948-
const songs = ['Back In Black', 'Stairway to Heaven', 'Hey Jude'];
1949-
const artists = ['ACDC', 'Led Zeppelin', 'The Beatles'];
1940+
const SONGS = ['Back In Black', 'Stairway to Heaven', 'Hey Jude'];
1941+
const ARTISTS = ['ACDC', 'Led Zeppelin', 'The Beatles'];
19501942

19511943
function eraseDatabase() {}
19521944
function restoreDatabase() {}
@@ -2180,5 +2172,9 @@ This is also available in other languages:
21802172
- [maksugr/clean-code-javascript](https://github.com/maksugr/clean-code-javascript)
21812173
- ![vi](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Vietnam.png) **Vietnamese**: [hienvd/clean-code-javascript/](https://github.com/hienvd/clean-code-javascript/)
21822174
- ![ja](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Japan.png) **Japanese**: [mitsuruog/clean-code-javascript/](https://github.com/mitsuruog/clean-code-javascript/)
2175+
- ![id](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Indonesia.png) **Indonesia**:
2176+
[andirkh/clean-code-javascript/](https://github.com/andirkh/clean-code-javascript/)
2177+
- ![it](https://raw.githubusercontent.com/gosquared/flags/master/flags/flags/shiny/24/Italy.png) **Italian**:
2178+
[frappacchio/clean-code-javascript/](https://github.com/frappacchio/clean-code-javascript/)
21832179

21842180
**[⬆ back to top](#table-of-contents)**

0 commit comments

Comments
 (0)