Skip to content

Commit c59069c

Browse files
committed
pre-move sketch to svg
1 parent a6284de commit c59069c

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

1-js/03-code-quality/02-coding-style/article.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,27 @@ A single-line construct, such as `if (condition) doSomething()`, is an important
5656

5757
Here are the annotated variants so you can judge their readability for yourself:
5858

59-
<!--
60-
```js no-beautify
61-
if (n < 0) {alert(`Power ${n} is not supported`);}
62-
63-
if (n < 0) alert(`Power ${n} is not supported`);
64-
65-
if (n < 0)
66-
alert(`Power ${n} is not supported`);
59+
1. 😠 Beginners sometimes do that. Bad! Curly braces are not needed:
60+
```js
61+
if (n < 0) *!*{*/!*alert(`Power ${n} is not supported`);*!*}*/!*
62+
```
63+
2. 😠 Split to a separate line without braces. Never do that, easy to make an error when adding new lines:
64+
```js
65+
if (n < 0)
66+
alert(`Power ${n} is not supported`);
67+
```
68+
3. 😏 One line without braces - acceptable, if it's short:
69+
```js
70+
if (n < 0) alert(`Power ${n} is not supported`);
71+
```
72+
4. 😃 The best variant:
73+
```js
74+
if (n < 0) {
75+
alert(`Power ${n} is not supported`);
76+
}
77+
```
6778
68-
if (n < 0) {
69-
alert(`Power ${n} is not supported`);
70-
}
71-
```
72-
-->
73-
![](figure-bracket-style.png)
79+
For a very brief code, one line is allowed, e.g. `if (cond) return null`. But a code block (the last variant) is usually more readable.
7480
7581
### Line Length
7682
@@ -106,9 +112,9 @@ There are two types of indents:
106112
107113
- **Horizontal indents: 2 or 4 spaces.**
108114
109-
A horizontal indentation is made using either 2 or 4 spaces or the "Tab" symbol. Which one to choose is an old holy war. Spaces are more common nowadays.
115+
A horizontal indentation is made using either 2 or 4 spaces or the horizontal tab symbol (key `key:Tab`). Which one to choose is an old holy war. Spaces are more common nowadays.
110116
111-
One advantage of spaces over tabs is that spaces allow more flexible configurations of indents than the "Tab" symbol.
117+
One advantage of spaces over tabs is that spaces allow more flexible configurations of indents than the tab symbol.
112118
113119
For instance, we can align the arguments with the opening bracket, like this:
114120
@@ -153,7 +159,7 @@ If you're an experienced JavaScript programmer, you may choose a no-semicolon co
153159
154160
Try to avoid nesting code too many levels deep.
155161
156-
For example, in the loop, it's sometimes a good idea to use the ["continue"](info:while-for#continue) directive to avoid extra nesting.
162+
For example, in the loop, it's sometimes a good idea to use the [`continue`](info:while-for#continue) directive to avoid extra nesting.
157163
158164
For example, instead of adding a nested `if` conditional like this:
159165
@@ -271,7 +277,7 @@ That's because when reading code, we first want to know *what it does*. If the c
271277
272278
## Style Guides
273279
274-
A style guide contains general rules about "how to write" code, e.g. which quotes to use, how many spaces to indent, where to put line breaks, etc. A lot of minor things.
280+
A style guide contains general rules about "how to write" code, e.g. which quotes to use, how many spaces to indent, the maximal line length, etc. A lot of minor things.
275281
276282
When all members of a team use the same style guide, the code looks uniform, regardless of which team member wrote it.
277283

figures.sketch

-192 KB
Binary file not shown.

0 commit comments

Comments
 (0)