|
1 | | -# Coding Style |
| 1 | +# Код стили боюнча кеңештер |
2 | 2 |
|
3 | | -Our code must be as clean and easy to read as possible. |
| 3 | +Биздин код мүмкүн болушунча түшүнүктүү жана окууга оңой болушу керек. |
4 | 4 |
|
5 | | -That is actually the art of programming -- to take a complex task and code it in a way that is both correct and human-readable. A good code style greatly assists in that. |
| 5 | +Чындыгында программалоо чеберчилиги -- бул татаал тапшырманы аткаруу жана аны туура жана адамга түшүнүктүү кылып коддоо. Жакшы код стили буга чоң жардам берет. |
6 | 6 |
|
7 | | -## Syntax |
| 7 | +## Синтаксис |
8 | 8 |
|
9 | | -Here is a cheat sheet with some suggested rules (see below for more details): |
| 9 | +Кээ бир сунушталган эрежелер бул сүрөттө келтирилген (кененирээк маалымат үчүн төмөндө караңыз): |
10 | 10 |
|
11 | 11 |  |
12 | 12 | <!-- |
@@ -34,79 +34,79 @@ if (n < 0) { |
34 | 34 |
|
35 | 35 | --> |
36 | 36 |
|
37 | | -Now let's discuss the rules and reasons for them in detail. |
| 37 | +Эми алардын эрежелерин жана себептерин кененирээк караштыралы. |
38 | 38 |
|
39 | | -```warn header="There are no \"you must\" rules" |
40 | | -Nothing is set in stone here. These are style preferences, not religious dogmas. |
| 39 | +```warn header="Милдеттүү эрежелер жок" |
| 40 | +Бул жерде эч кандай темирдей эрежелер жок. Булар стилдик артыкчылыктар, диний догмалар эмес. |
41 | 41 | ``` |
42 | 42 |
|
43 | | -### Curly Braces |
| 43 | +### Фигуралык кашаалар |
44 | 44 |
|
45 | 45 | In most JavaScript projects curly braces are written in "Egyptian" style with the opening brace on the same line as the corresponding keyword -- not on a new line. There should also be a space before the opening bracket, like this: |
46 | 46 |
|
47 | 47 | ```js |
48 | 48 | if (condition) { |
49 | | - // do this |
50 | | - // ...and that |
51 | | - // ...and that |
| 49 | + // муну кыл |
| 50 | + // ...муну дагы |
| 51 | + // ...муну дагы |
52 | 52 | } |
53 | 53 | ``` |
54 | 54 |
|
55 | 55 | A single-line construct, such as `if (condition) doSomething()`, is an important edge case. Should we use braces at all? |
56 | 56 |
|
57 | 57 | Here are the annotated variants so you can judge their readability for yourself: |
58 | 58 |
|
59 | | -1. 😠 Beginners sometimes do that. Bad! Curly braces are not needed: |
| 59 | +1. 😠 Кээде үйрөнчүктөр ушундай кылышат. Бул жаман мисал, фигуралык кашаалардын кереги жок: |
60 | 60 | ```js |
61 | | - if (n < 0) *!*{*/!*alert(`Power ${n} is not supported`);*!*}*/!* |
| 61 | + if (n < 0) *!*{*/!*alert(`${n} даражасы колдоого алынбайт`);*!*}*/!* |
62 | 62 | ``` |
63 | | -2. 😠 Split to a separate line without braces. Never do that, easy to make an error when adding new lines: |
| 63 | +2. 😠 Фигуралык кашаасыз саптарды эч качан бөлбөңүз - жаңы саптарды кошуп жатканда кокустан ката кетиши мүмкүн: |
64 | 64 | ```js |
65 | 65 | if (n < 0) |
66 | | - alert(`Power ${n} is not supported`); |
| 66 | + alert(`${n} даражасы колдоого алынбайт`); |
67 | 67 | ``` |
68 | | -3. 😏 One line without braces - acceptable, if it's short: |
| 68 | +3. 😏 Кашаасыз бир сапка жазуу - алгылыктуу вариант, эгерде сап кыска болсо: |
69 | 69 | ```js |
70 | | - if (n < 0) alert(`Power ${n} is not supported`); |
| 70 | + if (n < 0) alert(`${n} даражасы колдоого алынбайт`); |
71 | 71 | ``` |
72 | | -4. 😃 The best variant: |
| 72 | +4. 😃 Мыкты вариант: |
73 | 73 | ```js |
74 | 74 | if (n < 0) { |
75 | | - alert(`Power ${n} is not supported`); |
| 75 | + alert(`${n} даражасы колдоого алынбайт`); |
76 | 76 | } |
77 | 77 | ``` |
78 | 78 |
|
79 | 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. |
80 | 80 |
|
81 | | -### Line Length |
| 81 | +### Саптын узундугу |
82 | 82 |
|
83 | 83 | No one likes to read a long horizontal line of code. It's best practice to split them. |
84 | 84 |
|
85 | | -For example: |
| 85 | +Мисалы: |
86 | 86 | ```js |
87 | | -// backtick quotes ` allow to split the string into multiple lines |
| 87 | +// тескери тырмакча ` сапты бир нече бөлүктөргө бөлүүгө мүмкүндүк берет |
88 | 88 | let str = ` |
89 | | - ECMA International's TC39 is a group of JavaScript developers, |
90 | | - implementers, academics, and more, collaborating with the community |
91 | | - to maintain and evolve the definition of JavaScript. |
| 89 | + ECMA International уюмунун TC39 жумушчу тобу - бул JavaScript тилин |
| 90 | + колдоо жана өнүктүрүү үчүн коомдоштук менен биргелешип иштешкен JavaScript |
| 91 | + иштеп чыгуучулардын, интеграция боюнча адистердин, илимпоздордун ж.б. тобу. |
92 | 92 | `; |
93 | 93 | ``` |
94 | 94 |
|
95 | | -And, for `if` statements: |
| 95 | +Же `if` үчүн: |
96 | 96 |
|
97 | 97 | ```js |
98 | 98 | if ( |
99 | 99 | id === 123 && |
100 | | - moonPhase === 'Waning Gibbous' && |
101 | | - zodiacSign === 'Libra' |
| 100 | + moonPhase === 'Өсүп жаткан ай' && |
| 101 | + zodiacSign === 'Тараза' |
102 | 102 | ) { |
103 | 103 | letTheSorceryBegin(); |
104 | 104 | } |
105 | 105 | ``` |
106 | 106 |
|
107 | 107 | The maximum line length should be agreed upon at the team-level. It's usually 80 or 120 characters. |
108 | 108 |
|
109 | | -### Indents |
| 109 | +### Чегинүүлөр |
110 | 110 |
|
111 | 111 | There are two types of indents: |
112 | 112 |
|
|
0 commit comments