Skip to content

Commit 5a4a24b

Browse files
committed
feat(i18n): 1.03.03.article つづく
1 parent 228f94d commit 5a4a24b

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

1-js/03-code-quality/03-comments/article.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
# Comments
1+
# Komentar
22

3-
As we know from the chapter <info:structure>, comments can be single-line: starting with `//` and multiline: `/* ... */`.
3+
Seperti yang kita tahu dari bab <info:structure>, komentar bisa sebaris tunggal: mulai dari `//` dan baris-ganda: `/* ... */`.
44

5-
We normally use them to describe how and why the code works.
5+
Normalnya kita pakai mereka untuk menjelaskan bagaimana dan kenapa kode bekerja.
66

7-
At first sight, commenting might be obvious, but novices in programming often use them wrongly.
7+
Di awal pandangan, berkomentar itu sudah jelas, tapi pemula sering salah memakainya dalam pemrograman.
88

9-
## Bad comments
9+
## Komentar jelek
1010

11-
Novices tend to use comments to explain "what is going on in the code". Like this:
11+
Pemula cenderung memakai komentar untuk menjelaskan "ada apa di dalam kode". Seperti ini:
1212

1313
```js
14-
// This code will do this thing (...) and that thing (...)
15-
// ...and who knows what else...
14+
// Kode ini akan melakukan ini (...) dan itu (...)
15+
// ...dan entah apa lagi...
1616
very;
1717
complex;
1818
code;
1919
```
2020

21-
But in good code, the amount of such "explanatory" comments should be minimal. Seriously, the code should be easy to understand without them.
21+
Tapi di dalam kode yang baik, jumlah komentar "penjelasan" seperti ini sebaiknya minimal. Seriusnya, kode harus bisa dimengerti tanpa mereka.
2222

23-
There's a great rule about that: "if the code is so unclear that it requires a comment, then maybe it should be rewritten instead".
23+
Ada aturan besar tentang itu: "jika kode begitu tak jelas hingga ia butuh komentar, mungkin malah ia harus ditulis ulang".
2424

25-
### Recipe: factor out functions
25+
### Resep: fungsi faktor keluar
2626

27-
Sometimes it's beneficial to replace a code piece with a function, like here:
27+
Kadang menguntungkan untuk mengganti sepotong kode dengan fungsi, seperti ini:
2828

2929
```js
3030
function showPrimes(n) {
3131
nextPrime:
3232
for (let i = 2; i < n; i++) {
3333

3434
*!*
35-
// check if i is a prime number
35+
// cek apakah i angka prima
3636
for (let j = 2; j < i; j++) {
3737
if (i % j == 0) continue nextPrime;
3838
}
@@ -43,7 +43,7 @@ function showPrimes(n) {
4343
}
4444
```
4545

46-
The better variant, with a factored out function `isPrime`:
46+
Varian lebih baiknya, dengan fungsi faktor keluar `isPrime`:
4747

4848

4949
```js
@@ -65,21 +65,21 @@ function isPrime(n) {
6565
}
6666
```
6767

68-
Now we can understand the code easily. The function itself becomes the comment. Such code is called *self-descriptive*.
68+
Sekarang kita mudah mengerti kodenya. Fungsinya itu sendiri menjadi komentar. Kode macam ini disebut *menjelaskan-diri-sendiri*.
6969

70-
### Recipe: create functions
70+
### Resep: membuat fungsi
7171

72-
And if we have a long "code sheet" like this:
72+
Dan jika kita punya "code sheet" sangat panjang seperti ini:
7373

7474
```js
75-
// here we add whiskey
75+
// kita tambah \whiskey di sini
7676
for(let i = 0; i < 10; i++) {
7777
let drop = getWhiskey();
7878
smell(drop);
7979
add(drop, glass);
8080
}
8181

82-
// here we add juice
82+
// kita tambah jus di sini
8383
for(let t = 0; t < 3; t++) {
8484
let tomato = getTomato();
8585
examine(tomato);
@@ -90,7 +90,7 @@ for(let t = 0; t < 3; t++) {
9090
// ...
9191
```
9292

93-
Then it might be a better variant to refactor it into functions like:
93+
Maka mungkin varian lebih baiknya ialah merefaktornya menjadi fungsi seperti:
9494

9595
```js
9696
addWhiskey(glass);
@@ -111,13 +111,13 @@ function addJuice(container) {
111111
}
112112
```
113113

114-
Once again, functions themselves tell what's going on. There's nothing to comment. And also the code structure is better when split. It's clear what every function does, what it takes and what it returns.
114+
Sekali lagi, fungsi mereka sendiri menjelaskan apa yang terjadi. Tak ada yang dikomentari. Dan juga struktur kodenya lebih baik saat dipisah. Kelakuan tiap fungsi jadi lebih jelas, apa yang ia ambil dan yang ia kembalikan.
115115

116-
In reality, we can't totally avoid "explanatory" comments. There are complex algorithms. And there are smart "tweaks" for purposes of optimization. But generally we should try to keep the code simple and self-descriptive.
116+
Relitanya, kita tak bisa menghindar total dari komentar "penjelasan". Ada algoritma rumit. Dan ada "tweak" pintar dengan tujuan optimisasi. Tapi umumnya kita harus coba menjaga kodenya simpel dan menjelaskan-diri-sendiri.
117117

118-
## Good comments
118+
## Komentar baik
119119

120-
So, explanatory comments are usually bad. Which comments are good?
120+
Jadi, explanatory comments are usually bad. Which comments are good?
121121

122122
Describe the architecture
123123
: Provide a high-level overview of components, how they interact, what's the control flow in various situations... In short -- the bird's eye view of the code. There's a special language [UML](http://wikipedia.org/wiki/Unified_Modeling_Language) to build high-level architecture diagrams explaining the code. Definitely worth studying.
@@ -160,7 +160,7 @@ Why is the task solved this way?
160160
Any subtle features of the code? Where they are used?
161161
: If the code has anything subtle and counter-intuitive, it's definitely worth commenting.
162162

163-
## Summary
163+
## Kesimpulan
164164

165165
An important sign of a good developer is comments: their presence and even their absence.
166166

0 commit comments

Comments
 (0)