Skip to content

Commit 2a44730

Browse files
committed
function 1/2
1 parent a202797 commit 2a44730

File tree

1 file changed

+53
-44
lines changed

1 file changed

+53
-44
lines changed

README.md

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
1. [Kata Pengantar](#kata-pengantar)
55
2. [Variabel](#variabel)
66
3. [Fungsi](#fungsi)
7-
4. [Objects and Data Structures](#objects-and-data-structures)
8-
5. [Classes](#classes)
7+
4. [Objek dan Struktur Data](#objek-dan-struktur-data)
8+
5. [Class](#class)
99
6. [SOLID](#solid)
1010
7. [Testing](#testing)
1111
8. [Concurrency](#concurrency)
@@ -209,42 +209,45 @@ function createMicrobrewery(breweryName = 'Hipster Brew Co.') {
209209
**[⬆ Kembali ke atas](#daftar-isi)**
210210

211211
## **Fungsi**
212-
### Argumen Fungsi (idealnya 2 atau kurang)
213-
Limiting the amount of function parameters is incredibly important because it
214-
makes testing your function easier. Having more than three leads to a
215-
combinatorial explosion where you have to test tons of different cases with
216-
each separate argument.
217-
218-
One or two arguments is the ideal case, and three should be avoided if possible.
219-
Anything more than that should be consolidated. Usually, if you have
220-
more than two arguments then your function is trying to do too much. In cases
221-
where it's not, most of the time a higher-level object will suffice as an
222-
argument.
223-
224-
Since JavaScript allows you to make objects on the fly, without a lot of class
225-
boilerplate, you can use an object if you are finding yourself needing a
226-
lot of arguments.
212+
### Argumen Fungsi (idealnya hanya 2 atau kurang)
213+
Membatasi jumlah parameter dari fungsi sangatlah penting karena membuat pengujian
214+
fungsi menjadi lebih mudah. Memiliki lebih dari 3 parameter dapat mengakibatkan
215+
ledakan kombinasional dimana kamu harus menguji banyak sekali kasus-kasus yg
216+
berbeda di tiap-tiap argumen yg terpisah.
217+
218+
Satu atau dua argumen adalah kasus yg ideal, jika tiga maka sebaiknya dihindari.
219+
Apapun lebih dari itu harus dikonsolidasikan. Biasanya, jika kamu memiliki lebih
220+
dari dua argumen maka fungsimu melakukan hal yg terlalu banyak. Di beberapa kasus
221+
dimana hal itu tidak terjadi, seringkali higher-level object akan cukup menjadi
222+
sebuah argumen.
223+
224+
JavaScript memperbolehkanmu untuk membuat object secara langsung, tanpa membuat
225+
banyak class terlebih dahulu. kamu dapat menggunakan sebuah objek jika kamu
226+
mendapatibahwa kamu memerlukan banyak argumen.
227227

228228
To make it obvious what properties the function expects, you can use the ES2015/ES6
229229
destructuring syntax. This has a few advantages:
230230

231-
1. When someone looks at the function signature, it's immediately clear what
232-
properties are being used.
233-
2. Destructuring also clones the specified primitive values of the argument
234-
object passed into the function. This can help prevent side effects. Note:
235-
objects and arrays that are destructured from the argument object are NOT
236-
cloned.
237-
3. Linters can warn you about unused properties, which would be impossible
238-
without destructuring.
231+
Lebih jelasnya, kamu dapat menggunakan destructuring syntax pada ES2015/ES6. Hal
232+
tersebut memiliki beberapa kelebihan:
239233

240-
**Bad:**
234+
1. Ketika seseorang melihat fungsi, fungsi tersebut secara langsung menjelaskan
235+
properti-properti apa saja yg digunakan.
236+
2. Merestrukturisasi juga mengkloning nilai primitif yang ditentukan dari objek
237+
argumen yang dilewatkan ke fungsi. Hal ini dapat membantu mencegah efek samping.
238+
Sebagai Catatan: objek dan array yg telah didestrukturisasi dari argumen objek
239+
tidak di kloning.
240+
3. Linters dapat memberi peringatan kepadamu tentang properti yg tidak digunakan,
241+
yg mana akan lebih tidak mungkin tanpa merestrukturisasi.
242+
243+
**Buruk:**
241244
```javascript
242245
function createMenu(title, body, buttonText, cancellable) {
243246
// ...
244247
}
245248
```
246249

247-
**Good:**
250+
**Baik:**
248251
```javascript
249252
function createMenu({ title, body, buttonText, cancellable }) {
250253
// ...
@@ -260,14 +263,20 @@ createMenu({
260263
**[⬆ back to top](#table-of-contents)**
261264

262265

263-
### Functions should do one thing
266+
### Fungsi harus melakukan satu hal saja
264267
This is by far the most important rule in software engineering. When functions
265268
do more than one thing, they are harder to compose, test, and reason about.
266269
When you can isolate a function to just one action, they can be refactored
267270
easily and your code will read much cleaner. If you take nothing else away from
268271
this guide other than this, you'll be ahead of many developers.
269272

270-
**Bad:**
273+
Ini adalah aturan terpenting dalam rekayasa perangkat lunak. Ketika fungsi melakukan
274+
lebih dari satu hal, mereka sulit untuk dibuat, diuji dan dipikirkan. Ketika kamu
275+
dapat mengisolasi sebuah fungsi untuk melakukan satu action saja, mereka dapat
276+
difaktorkan secara mudah dan kodemu akan jauh lebih bersih. Jika kamu tidak mengambil
277+
apapun dari panduan ini selain hal ini, maka anda akan ada di depan banyak pengembang.
278+
279+
**Buruk:**
271280
```javascript
272281
function emailClients(clients) {
273282
clients.forEach((client) => {
@@ -279,7 +288,7 @@ function emailClients(clients) {
279288
}
280289
```
281290

282-
**Good:**
291+
**Baik:**
283292
```javascript
284293
function emailActiveClients(clients) {
285294
clients
@@ -292,23 +301,23 @@ function isActiveClient(client) {
292301
return clientRecord.isActive();
293302
}
294303
```
295-
**[back to top](#table-of-contents)**
304+
**[Kembali ke atas](#daftar-isi)**
296305

297-
### Function names should say what they do
306+
### Nama dari fungsi harus mewakili apa yg dia lakukan
298307

299-
**Bad:**
308+
**Buruk:**
300309
```javascript
301310
function addToDate(date, month) {
302311
// ...
303312
}
304313

305314
const date = new Date();
306315

307-
// It's hard to to tell from the function name what is added
316+
// sulit untuk mengatakan dari nama fungsi yg ditambahkan
308317
addToDate(date, 1);
309318
```
310319

311-
**Good:**
320+
**Baik:**
312321
```javascript
313322
function addMonthToDate(month, date) {
314323
// ...
@@ -317,14 +326,14 @@ function addMonthToDate(month, date) {
317326
const date = new Date();
318327
addMonthToDate(1, date);
319328
```
320-
**[back to top](#table-of-contents)**
329+
**[Kembali ke atas](#daftar-isi)**
321330

322-
### Functions should only be one level of abstraction
323-
When you have more than one level of abstraction your function is usually
324-
doing too much. Splitting up functions leads to reusability and easier
325-
testing.
331+
### Fungsi-fungsi seharusnya satu tingkat abstraksi
332+
Ketika kamu memiliki lebih dari satu tingkat abstraksi, fungsimu biasanya melakukan
333+
hal yg terlalu banyak. Memisah-misah fungsi dapat meningkatkan reusabilitas dan
334+
memudahkan pengujian.
326335

327-
**Bad:**
336+
**Buruk:**
328337
```javascript
329338
function parseBetterJSAlternative(code) {
330339
const REGEXES = [
@@ -350,7 +359,7 @@ function parseBetterJSAlternative(code) {
350359
}
351360
```
352361

353-
**Good:**
362+
**Baik:**
354363
```javascript
355364
function tokenize(code) {
356365
const REGEXES = [
@@ -385,9 +394,9 @@ function parseBetterJSAlternative(code) {
385394
});
386395
}
387396
```
388-
**[back to top](#table-of-contents)**
397+
**[Kembali ke atas](#daftar-isi)**
389398

390-
### Remove duplicate code
399+
### Hapus kode yg duplikat
391400
Do your absolute best to avoid duplicate code. Duplicate code is bad because it
392401
means that there's more than one place to alter something if you need to change
393402
some logic.

0 commit comments

Comments
 (0)