# Refinement & Refactoring

### Successive Refinement

* Write a draft or "monolith" first
* Refine/refactor it

### Coding Cycle

* Think
* Code
* Think again
* Optimize/refactor

### Modifications

* Refactor first, write code after that
* Change the "pseudo code" first, the real code after that
* Refactor to isolate changed part

### Refactoring

* Refactoring is good, technical debt is bad
* Refactoring is a mandatory part of the iterative development
* Continuously refactor unclean code to clean code
* Always refactor for changes in the requirements - *"Until now the program had to do this, from now on the program has to do that"*

### Design Patterns

(Not part of this training. See links.)


---

# 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://petozoltan.gitbook.io/clearcode/clean-code/clean-code-outline/refinement-and-refactoring.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.
