# manual-checked-division

Prefer checked division over manual zero guards

Guarding an unsigned division or remainder operation with a zero comparison
manually implements checked division.
Instead, you SHOULD use the corresponding checked method and handle its `undefined` result.

- Category: style
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function divide(value: uint32, divisor: uint32): uint32 | undefined {
    if (divisor != 0) {
        return value / divisor;
    }

    return undefined;
}
```

## Accepted

```ds title="main.ds"
function divide(value: uint32, divisor: uint32): uint32 | undefined {
    return value.checkedDivide(divisor);
}
```

## Prior art

- [Clippy · manual_checked_ops](https://rust-lang.github.io/rust-clippy/master/index.html#manual_checked_ops)

[language/linter/src/rules/style/manual_checked_division.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/manual_checked_division.rs#L7)
