Skip to content

Commit 04c34cc

Browse files
committed
feat(i18n): 1.03.02.article
1 parent fb43a08 commit 04c34cc

File tree

1 file changed

+90
-90
lines changed

1 file changed

+90
-90
lines changed
Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Coding Style
1+
# Gaya Mengkode
22

3-
Our code must be as clean and easy to read as possible.
3+
Kode kita harus sebisa mungkin bersih dan mudah dibaca.
44

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+
Ini sebenarnya seni pemrograman -- ambil tugas rumit dan mengkodenya dengan cara yang benar dan dapat dibaca manusia. Gaya kode yang baik punya andil besar di situ.
66

77
## Syntax
88

9-
Here is a cheat sheet with some suggested rules (see below for more details):
9+
Ini adalah satu cheatsheet dengan beberapa aturan yang disarankan (lihat bawah untuk lebih detil):
1010

1111
![](code-style.svg)
1212
<!--
@@ -34,65 +34,65 @@ if (n < 0) {
3434
3535
-->
3636

37-
Now let's discuss the rules and reasons for them in detail.
37+
Sekarang kita bahas aturannya dan alasannya secara detil.
3838

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="Tak ada aturan yang memaksa"
40+
Tak ada yang diset sekeras batu di sini. Mereka cuma preferensi gaya saja, buka dogma agama.
4141
```
4242

43-
### Curly Braces
43+
### Kurung Kurawal
4444

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:
45+
Di kebanyakan proyek JavaScript kurung kurawal ditulis dalam gaya "Egyptian" dengan kurawal buka di baris yang sama dengan katakunci -- bukan di baris baru. Juga harus ada spasi sebelum bracket pembuka, seperti ini:
4646

4747
```js
4848
if (condition) {
49-
// do this
50-
// ...and that
51-
// ...and that
49+
// lakukan ini
50+
// ...dan itu
51+
// ...dan itu
5252
}
5353
```
5454

55-
A single-line construct, such as `if (condition) doSomething()`, is an important edge case. Should we use braces at all?
55+
Konstruksi sebaris, seperti `if (condition) doSomething()`, ialah hal penting sampingan. Haruskah kita memakai kurawal sama sekali?
5656

57-
Here are the annotated variants so you can judge their readability for yourself:
57+
Ini adalah varian yang teranotasi jadi kamu bisa menilai sendiri keterbacaan mereka:
5858

59-
1. 😠 Beginners sometimes do that. Bad! Curly braces are not needed:
59+
1. 😠 Pemula kadang melakukan itu. Buruk! Kurung kurawal tak dibutuhkan:
6060
```js
6161
if (n < 0) *!*{*/!*alert(`Power ${n} is not supported`);*!*}*/!*
6262
```
63-
2. 😠 Split to a separate line without braces. Never do that, easy to make an error when adding new lines:
63+
2. 😠 Pisahkan baris berbeda tanpa kurawal. Jangan pernah lakukan, mudah membuat galat saat menambah baris baru:
6464
```js
6565
if (n < 0)
6666
alert(`Power ${n} is not supported`);
6767
```
68-
3. 😏 One line without braces - acceptable, if it's short:
68+
3. 😏 Sebaris tanpa kurawal - bisa diterima, jika pendek:
6969
```js
7070
if (n < 0) alert(`Power ${n} is not supported`);
7171
```
72-
4. 😃 The best variant:
72+
4. 😃 Varian terbaik:
7373
```js
7474
if (n < 0) {
7575
alert(`Power ${n} is not supported`);
7676
}
7777
```
7878
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.
79+
Untuk kode ringkas, sebaris dibolehkan, misal `if (cond) return null`. Tapi blok kode (varian terakhir) biasanya lebih dapat terbaca.
8080
81-
### Line Length
81+
### Panjang Baris
8282
83-
No one likes to read a long horizontal line of code. It's best practice to split them.
83+
Tak ada orang suka membaca kode horizontal yang panjang. Memisahkan mereka ialah praktik yang baik.
8484
85-
For example:
85+
Misalnya:
8686
```js
87-
// backtick quotes ` allow to split the string into multiple lines
87+
// backtick quote ` memperbolehkan memecah string jadi beberapa baris
8888
let str = `
8989
Ecma International's TC39 is a group of JavaScript developers,
9090
implementers, academics, and more, collaborating with the community
9191
to maintain and evolve the definition of JavaScript.
9292
`;
9393
```
9494
95-
And, for `if` statements:
95+
Dan, untuk pernyataan `if`:
9696
9797
```js
9898
if (
@@ -104,23 +104,23 @@ if (
104104
}
105105
```
106106
107-
The maximum line length should be agreed upon at the team-level. It's usually 80 or 120 characters.
107+
Panjang baris maximum sebaiknya disepakati di level-tim. Biasanya 80 atau 120 karakter.
108108
109-
### Indents
109+
### Indent
110110
111-
There are two types of indents:
111+
Ada dua tipe indent:
112112
113-
- **Horizontal indents: 2 or 4 spaces.**
113+
- **Indent horizontal: 2 atau 4 spasi.**
114114
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.
115+
Indentasi horizontal dibuat menggunakan 2 atau 4 spasi atau simbol tab horizontal (kunci `key:Tab`). Pemilihan ini sudah lama jadi perang suci. Spasi jadi lebih umum sekarang ini.
116116
117-
One advantage of spaces over tabs is that spaces allow more flexible configurations of indents than the tab symbol.
117+
Satu keutamaan spasi dari tab ialah konfigurasi indent spasi lebih flexibel dari simbol tab.
118118
119-
For instance, we can align the arguments with the opening bracket, like this:
119+
Misalnya, kita bisa mengalinea argumen dengan bracket pembuka, seperti ini:
120120
121121
```js no-beautify
122122
show(parameters,
123-
aligned, // 5 spaces padding at the left
123+
aligned, // 5 padding spasi di kiri
124124
one,
125125
after,
126126
another
@@ -129,9 +129,9 @@ There are two types of indents:
129129
}
130130
```
131131
132-
- **Vertical indents: empty lines for splitting code into logical blocks.**
132+
- **Indent vertikal: baris kosong untuk memecah kode menjadi blok logika.**
133133
134-
Even a single function can often be divided into logical blocks. In the example below, the initialization of variables, the main loop and returning the result are split vertically:
134+
Bahkan satu fungsi pun sering bisa dibagi jadi blok logika. Di contoh berikut, inisialisasi variabel, loop utama dan hasil kembalian dipecah secara vertikal:
135135
136136
```js
137137
function pow(x, n) {
@@ -145,46 +145,46 @@ There are two types of indents:
145145
}
146146
```
147147
148-
Insert an extra newline where it helps to make the code more readable. There should not be more than nine lines of code without a vertical indentation.
148+
Sisipkan extra baris baru di mana ini membantu membuat kode lebih terbaca. Tak boleh lebih dari sembilan baris kode tanpa indentasi vertikal.
149149
150-
### Semicolons
150+
### Semicolon
151151
152-
A semicolon should be present after each statement, even if it could possibly be skipped.
152+
Semicolon sebaiknya ada di tiap ujung pernyataan, bahkan meski jika itu bisa dilewati.
153153
154-
There are languages where a semicolon is truly optional and it is rarely used. In JavaScript, though, there are cases where a line break is not interpreted as a semicolon, leaving the code vulnerable to errors. See more about that in the chapter <info:structure#semicolon>.
154+
Ada bahasa di mana semicolon benar-benar opsional dan jarang dipakai. Tapi di JavaScript, ada kasus di mana line break tidak diinterpretasi sebagai semicolon, membuat kode rentan galat. Lihat lebih lanjut tentang itu di bab <info:structure#semicolon>.
155155
156-
If you're an experienced JavaScript programmer, you may choose a no-semicolon code style like [StandardJS](https://standardjs.com/). Otherwise, it's best to use semicolons to avoid possible pitfalls. The majority of developers put semicolons.
156+
Jika kamu programmer JavaScript berpengalaman, kamu bisa pilih gaya kode tanpa semicolon seperti [StandardJS](https://standardjs.com/). Atau, lebih baik memakai semicolon untuk menghindari kemungkinan jurang nista. Mayoritas pengembang menaruh semicolon.
157157
158-
### Nesting Levels
158+
### Level Bersarang
159159
160-
Try to avoid nesting code too many levels deep.
160+
Coba hindari kode bersarang dengan level terlalu dalam.
161161
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.
162+
Misalnya, dalam loop, kadang ide bagus memakai directive [`continue`](info:while-for#continue) untuk menghindari sarang extra.
163163
164-
For example, instead of adding a nested `if` conditional like this:
164+
Misalnya, ketimbang menambah kondisional `if` bersarang seperti ini:
165165
166166
```js
167167
for (let i = 0; i < 10; i++) {
168168
if (cond) {
169-
... // <- one more nesting level
169+
... // <- satu lagi level bersarang
170170
}
171171
}
172172
```
173173
174-
We can write:
174+
Kita bisa tulis:
175175
176176
```js
177177
for (let i = 0; i < 10; i++) {
178178
if (!cond) *!*continue*/!*;
179-
... // <- no extra nesting level
179+
... // <- tak ada extra level bersarang
180180
}
181181
```
182182
183-
A similar thing can be done with `if/else` and `return`.
183+
Hal serupa bisa dilakukan dengan `if/else` dan `return`.
184184
185-
For example, two constructs below are identical.
185+
Misalnya, dua konstruksi berikut identik.
186186
187-
Option 1:
187+
Opsi 1:
188188
189189
```js
190190
function pow(x, n) {
@@ -202,7 +202,7 @@ function pow(x, n) {
202202
}
203203
```
204204
205-
Option 2:
205+
Opsi 2:
206206
207207
```js
208208
function pow(x, n) {
@@ -221,16 +221,16 @@ function pow(x, n) {
221221
}
222222
```
223223
224-
The second one is more readable because the "special case" of `n < 0` is handled early on. Once the check is done we can move on to the "main" code flow without the need for additional nesting.
224+
Yang kedua lebih terbaca karena "kasus spesial" `n < 0` ditangani segera. Sekali pengecekan selesai kita bisa pindah ke aliran kode "utama" tanpa sarang tambahan.
225225
226-
## Function Placement
226+
## Penempatan Fungsi
227227
228-
If you are writing several "helper" functions and the code that uses them, there are three ways to organize the functions.
228+
Jika kamu menulis beberapa fungsi "pembantu" dan kode yang menggunakan mereka, ada tiga cara untuk mengorganisir fungsi.
229229
230-
1. Declare the functions *above* the code that uses them:
230+
1. Deklarasi fungsi *di atas* kode yang menggunakan mereka:
231231
232232
```js
233-
// *!*function declarations*/!*
233+
// *!*deklarasi fungsi*/!*
234234
function createElement() {
235235
...
236236
}
@@ -243,20 +243,20 @@ If you are writing several "helper" functions and the code that uses them, there
243243
...
244244
}
245245

246-
// *!*the code which uses them*/!*
246+
// *!*kode yang menggunakan mereka*/!*
247247
let elem = createElement();
248248
setHandler(elem);
249249
walkAround();
250250
```
251-
2. Code first, then functions
251+
2. Kode pertama, lalu fungsi
252252
253253
```js
254-
// *!*the code which uses the functions*/!*
254+
// *!*kode yang menggunakan mereka*/!*
255255
let elem = createElement();
256256
setHandler(elem);
257257
walkAround();
258258

259-
// --- *!*helper functions*/!* ---
259+
// --- *!*fungsi pembantu*/!* ---
260260
function createElement() {
261261
...
262262
}
@@ -269,54 +269,54 @@ If you are writing several "helper" functions and the code that uses them, there
269269
...
270270
}
271271
```
272-
3. Mixed: a function is declared where it's first used.
272+
3. Campuran: fungsi dideklarasi di mana ia pertama dipakai.
273273
274-
Most of time, the second variant is preferred.
274+
Seringnya, varian kedua jadi pilihan.
275275
276-
That's because when reading code, we first want to know *what it does*. If the code goes first, then it becomes clear from the start. Then, maybe we won't need to read the functions at all, especially if their names are descriptive of what they actually do.
276+
Itu karena saat membaca kode, kita pertama mau tahu *itu bisa apa*. Jika kode mulai duluan, maka jadi lebih jelas dari awal. Lalu, mungkin kita tak mau membaca fungsinya sama sekali, terutama jika nama mereka deskriptif, sesuai dengan kelakuan mereka.
277277
278-
## Style Guides
278+
## Panduan Gaya
279279
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.
280+
Panguan gaya berisi aturan umum tentang "bagaimana menulis" kode, misal quote mana yang dipakai, berapa spasi indent, panjang baris maximal, dll. Banyak hal remeh.
281281
282-
When all members of a team use the same style guide, the code looks uniform, regardless of which team member wrote it.
282+
Saat semua anggota tim menggunakan panduan gaya yang sama, kodenya terlihat seragam, tak peduli anggota tim mana yang menulisnya.
283283
284-
Of course, a team can always write their own style guide, but usually there's no need to. There are many existing guides to choose from.
284+
Tentu saja, tim bisa saja menulis panduan gaya mereka sendiri, tapi biasanya mereka tak butuh. There are many existing guides to choose from.
285285
286-
Some popular choices:
286+
Beberapa pilihan populer:
287287
288-
- [Google JavaScript Style Guide](https://google.github.io/styleguide/javascriptguide.xml)
289-
- [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript)
288+
- [Panduan Gaya JavaScript Google](https://google.github.io/styleguide/javascriptguide.xml)
289+
- [Panduan Gaya JavaScript Airbnb](https://github.com/airbnb/javascript)
290290
- [Idiomatic.JS](https://github.com/rwaldron/idiomatic.js)
291291
- [StandardJS](https://standardjs.com/)
292-
- (plus many more)
292+
- (plus banyak lainnya)
293293
294-
If you're a novice developer, start with the cheat sheet at the beginning of this chapter. Then you can browse other style guides to pick up more ideas and decide which one you like best.
294+
Jika kamu pengembang pemula, mulai dengan cheatsheet di awal bab ini. Lalu kamu bisa menjelajah panduan gaya lain untuk mencari ide lebih dan menentukan mana yang terbaik.
295295
296-
## Automated Linters
296+
## Linter Terotomasi
297297
298-
Linters are tools that can automatically check the style of your code and make improving suggestions.
298+
Linter ialah tool yang bisa otomatis mengecek gaya kodemu dan memberi saran improvisasi.
299299
300-
The great thing about them is that style-checking can also find some bugs, like typos in variable or function names. Because of this feature, using a linter is recommended even if you don't want to stick to one particular "code style".
300+
Yang keren dari ini ialah pengecekan gaya sekaligus menemukan bug., like typos in variable or function names. Because of this feature, using a linter is recommended even if you don't want to stick to one particular "code style".
301301
302-
Here are some well-known linting tools:
302+
Berikut beberapa linting tool terkenal:
303303
304304
- [JSLint](http://www.jslint.com/) -- one of the first linters.
305305
- [JSHint](http://www.jshint.com/) -- more settings than JSLint.
306306
- [ESLint](http://eslint.org/) -- probably the newest one.
307307
308-
All of them can do the job. The author uses [ESLint](http://eslint.org/).
308+
Semuanya bisa melakukan itu. Penulis ini menggunakan [ESLint](http://eslint.org/).
309309
310-
Most linters are integrated with many popular editors: just enable the plugin in the editor and configure the style.
310+
Kebanyakan linter terintegrasi dengan banyak editor populer: cuma mengaktifkan plugin di editor dan mengkonfigurasi gayanya.
311311
312-
For instance, for ESLint you should do the following:
312+
Misalnya, untuk ESLint kamu harus melakukan hal ini:
313313
314-
1. Install [Node.js](https://nodejs.org/).
315-
2. Install ESLint with the command `npm install -g eslint` (npm is a JavaScript package installer).
316-
3. Create a config file named `.eslintrc` in the root of your JavaScript project (in the folder that contains all your files).
317-
4. Install/enable the plugin for your editor that integrates with ESLint. The majority of editors have one.
314+
1. Instal [Node.js](https://nodejs.org/).
315+
2. Instal ESLint dengan command `npm install -g eslint` (npm ialah installer package JavaScript).
316+
3. Buat file konfig bernama `.eslintrc` di root proyek JavaScriptmu (di folder yang berisi semua filemu).
317+
4. Instal/aktifkan plugin untuk editormu yang berintegrasi dengan ESLint. Mayoritas editor punya satu.
318318
319-
Here's an example of an `.eslintrc` file:
319+
Berikut contoh file `.eslintrc`:
320320
321321
```js
322322
{
@@ -333,16 +333,16 @@ Here's an example of an `.eslintrc` file:
333333
}
334334
```
335335
336-
Here the directive `"extends"` denotes that the configuration is based on the "eslint:recommended" set of settings. After that, we specify our own.
336+
Di sini directive `"extends"` menunjukkan bahwa konfigurasinya berdasarkan set pengaturan "eslint:recommended". Setelah itu, kita spesifikasikan punya kita sendiri.
337337
338-
It is also possible to download style rule sets from the web and extend them instead. See <http://eslint.org/docs/user-guide/getting-started> for more details about installation.
338+
Selain itu, dimungkinkan juga mengunduh set aturan gaya dari web dan mengextend mereka. Lihat <http://eslint.org/docs/user-guide/getting-started> untuk detil lebih tentang instalasi.
339339
340-
Also certain IDEs have built-in linting, which is convenient but not as customizable as ESLint.
340+
Juga IDE tertentu punya linting built-in, yang nyaman tapi tak bisa dikustomisasi seperti ESLint.
341341
342-
## Summary
342+
## Kesimpulan
343343
344-
All syntax rules described in this chapter (and in the style guides referenced) aim to increase the readability of your code. All of them are debatable.
344+
Semua aturan syntax yang dideskripsikan di bab ini (dan di referensi panduan gaya) bertujuan untuk meningkatkan keterbacaan kodemu. Mereka dapat diperdebatkan.
345345
346-
When we think about writing "better" code, the questions we should ask ourselves are: "What makes the code more readable and easier to understand?" and "What can help us avoid errors?" These are the main things to keep in mind when choosing and debating code styles.
346+
Saat kita berpikir tentang menulis kode "lebih baik", pertanyaannya ialah haruskah kita tanya diri kita sendiri: "Apa yang membuat kode dapat lebih terbaca dan lebih mudah dipahami?" dan "Apa yang bisa membantu kita menghindari galat?" Inilah hal utama yang harus dipikirkan saat memilih dan memperdebatkan gaya kode.
347347
348-
Reading popular style guides will allow you to keep up to date with the latest ideas about code style trends and best practices.
348+
Membaca panduan gaya populer akan membuatmu selalu terupdate dengan ide terbaru tentang tren gaya kode dan praktik terbaiknya.

0 commit comments

Comments
 (0)