# Clean Code

## Ultimate Purpose

Tujuan akhir dari clean code adalah agar code dapat dengan **mudah** dan **cepat** untuk:

1. Memahami apa maksud dari suatu code
2. Mengubah/memodifikasi code tersebut

## Kesalahan yang Sering Ditemukan

### 1) Meaningful Names

Gunakan nama yang memenuhi kriteria ini untuk variabel, fungsi, kelas, file, dll:

1. Mengungkapkan intensi tanpa perlu penjelasan lebih lanjut
2. Menghindari kesalahpahaman

Contoh kurang baik:

```javascript
const dateStart = moment(start_date).startOf('day')
const isSameDate = dateStart.isSame(new Date(), 'day')

if ((status === 0) && (isSameDate)) {
  this.btnDisableDate = false
}
```

Contoh lebih baik:

```javascript
const SurveyStatus = Object.freeze({
    DRAFT: 0,
    ACTIVE: 10
});
const isStartedToday = dateStart.isSame(new Date(), 'day')

// jika status sama dengan draft dan tanggal mulai sama dengan hari ini
if ((status === SurveyStatus.DRAFT && isStartedToday)) {
  this.btnDisableDate = false
}
```

Perhatikan bahwa:&#x20;

1. Dengan mendefinisikan nilai konstan sebagai variabel seperti `status === SurveyStatus.DRAFT` lebih mudah dipahami ketimbang `status === 0`.
2. Penamaan variabel `isStartedToday` lebih jelas intensinya ketimbang `isSameDate`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jabardigitalservice.gitbook.io/sapawarga/faq-1/clean-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
