docs: Fix readability docs — Five supports DEFER too
Five's DEFER is Go's defer in PRG syntax. Same safety guarantee, but without if err != nil pollution. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -131,27 +131,35 @@ Hungarian notation makes types visible in names:
|
||||
|
||||
Even AI-generated code is self-documenting with these prefixes.
|
||||
|
||||
### 4. Error handling doesn't pollute business logic
|
||||
### 4. DEFER keeps it safe AND clean
|
||||
|
||||
```go
|
||||
// Go — more error handling than business logic
|
||||
result, err := doSomething()
|
||||
// Go — defer exists but err checks pollute the code
|
||||
db, err := sql.Open("sqlite3", dsn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("doSomething failed: %w", err)
|
||||
return fmt.Errorf("open failed: %w", err)
|
||||
}
|
||||
result2, err := doAnother(result)
|
||||
defer db.Close()
|
||||
result, err := db.Query("SELECT ...")
|
||||
if err != nil {
|
||||
return fmt.Errorf("doAnother failed: %w", err)
|
||||
return fmt.Errorf("query failed: %w", err)
|
||||
}
|
||||
defer result.Close()
|
||||
```
|
||||
|
||||
```prg
|
||||
// Five — focus on business logic
|
||||
result := doSomething()
|
||||
result2 := doAnother(result)
|
||||
// Errors handled in one place via BEGIN SEQUENCE or ErrorBlock
|
||||
// Five — DEFER + clean business logic
|
||||
db := sql.Open("sqlite", dsn)
|
||||
DEFER db:Close() // Same as Go's defer!
|
||||
|
||||
result := SqlScan(db, "SELECT ...")
|
||||
// Errors handled in one place via BEGIN SEQUENCE
|
||||
// But the code stays readable
|
||||
```
|
||||
|
||||
Five brings Go's `defer` as `DEFER` — same safety, same guarantee.
|
||||
The good parts of Go, without the `if err != nil` noise.
|
||||
|
||||
## AI-Era Scenarios
|
||||
|
||||
### Scenario 1: AI service goes down
|
||||
|
||||
@@ -169,27 +169,35 @@ lIsActive := .T.
|
||||
|
||||
AI가 코드를 작성해도, 변수명만 보면 타입을 알 수 있습니다.
|
||||
|
||||
### 4. 에러 처리가 코드를 오염시키지 않는다
|
||||
### 4. DEFER로 안전하면서도 깔끔하다
|
||||
|
||||
```go
|
||||
// Go — 비즈니스 로직보다 에러 처리가 더 많음
|
||||
result, err := doSomething()
|
||||
// Go — defer는 있지만 err 체크가 코드를 오염
|
||||
db, err := sql.Open("sqlite3", dsn)
|
||||
if err != nil {
|
||||
return fmt.Errorf("doSomething failed: %w", err)
|
||||
return fmt.Errorf("open failed: %w", err)
|
||||
}
|
||||
result2, err := doAnother(result)
|
||||
defer db.Close()
|
||||
result, err := db.Query("SELECT ...")
|
||||
if err != nil {
|
||||
return fmt.Errorf("doAnother failed: %w", err)
|
||||
return fmt.Errorf("query failed: %w", err)
|
||||
}
|
||||
defer result.Close()
|
||||
```
|
||||
|
||||
```prg
|
||||
// Five — 비즈니스 로직에 집중
|
||||
result := doSomething()
|
||||
result2 := doAnother(result)
|
||||
// 에러는 BEGIN SEQUENCE나 ErrorBlock으로 한 곳에서 처리
|
||||
// Five — DEFER + 깔끔한 비즈니스 로직
|
||||
db := sql.Open("sqlite", dsn)
|
||||
DEFER db:Close() // Go의 defer와 동일!
|
||||
|
||||
result := SqlScan(db, "SELECT ...")
|
||||
// 에러는 BEGIN SEQUENCE로 한 곳에서 처리
|
||||
// 그런데 코드는 읽기 쉬움
|
||||
```
|
||||
|
||||
Five는 Go의 `defer`를 `DEFER`로 그대로 지원합니다.
|
||||
Go의 좋은 점은 가져오되, `if err != nil` 반복은 없앱니다.
|
||||
|
||||
## AI 시대 시나리오
|
||||
|
||||
### 시나리오 1: AI 서비스가 중단됨
|
||||
|
||||
Reference in New Issue
Block a user