Vim/STYLE.md

32 lines
1.2 KiB
Markdown
Raw Normal View History

2016-07-13 22:29:29 +03:00
## Style Guide
2016-09-28 09:16:48 +03:00
In addition, to VS Code's [coding guidelines](https://github.com/Microsoft/vscode/wiki/Coding-Guidelines), please adhere to the following:
2018-07-29 12:27:28 +03:00
- Use `for ... of` whenever possible
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
**Rationale:** `for ... of` is awesome. It's more readable than any other variant.
2016-07-13 22:29:29 +03:00
2018-07-29 12:27:28 +03:00
- Don't use `any` as much as possible
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
**Rationale:** The language is called *Type*Script, not *Untyped*Script. :wink: Static typing is wonderful. It catches bugs and improves readability. We should strive to use it as much as possible.
2016-07-13 22:29:29 +03:00
2018-07-29 12:27:28 +03:00
- Use `const` wherever possible.
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
**Rationale:** Instead of reading `const` as "constant value," read it as "single assignment." Yes, it means "constant value" in other programming languages, but it's a little different in JavaScript.
2016-07-13 22:29:29 +03:00
2018-07-29 12:27:28 +03:00
- When we can't use `const`, use `let`; never `var`
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
**Rationale:** `var` trips up programmers in a number of cases - hoisting and closure capture are two big ones. Consider the difference between
```
for (var j = 0; j < 5; j++) { setTimeout(() => console.log(j), 5) }
```
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
and
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
```
for (let j = 0; j < 5; j++) { setTimeout(() => console.log(j), 5) }
```
2016-07-13 22:29:29 +03:00
2016-09-28 09:16:48 +03:00
Even if you're not capturing the variable, who knows if someone else might later?