Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit dd909e7

Browse files
committed
Add notes on conditional comment placement.
1 parent c87ddf3 commit dd909e7

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

javascript/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,26 @@ var showFooter = !$('.shopping-bag').length;
1414
var showFooter = !$('.shopping-bag').length;
1515
````
1616

17+
Place comments that explain conditionals above the condition. This saves you four precious spaces of indent:
18+
19+
````javascript
20+
21+
if (condition) {
22+
// BAD! ☠
23+
// When `condition` is set we really need to `doSomething()`.
24+
doSomething();
25+
}
26+
27+
// GOOD ☆
28+
// When `condition` is set we really need to `doSomething()`.
29+
if (condition) {
30+
doSomething();
31+
}
32+
````
33+
34+
In general, always favour comment placement that leads to less indenting.
35+
36+
1737
Don't commit commented out sections of code back into the repository. Just delete the code. That's what git's history is for!
1838

1939
If a piece of code is very temporarily being removed, and will be reinserted shortly, you might decide to do this anyway. Please leave a detailed comment explaining exactly why. Sorta like those post-its we leave on boxes in the fridge with our name and date so that we know when to chuck 'em out!

0 commit comments

Comments
 (0)