# prefer-method

Prefer methods when the first parameter establishes a receiver

A function whose first parameter supplies the operation's canonical nominal owner hides that operation from member lookup.
Instead, you SHOULD declare an inherent or extension method.

Symmetric operations, constructors, decorated functions, and ambient declarations remain free functions.

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

## Reported

```ds title="main.ds"
struct Counter {
    value: int32;
}

function increment(counter: &exclusive Counter): void {
    counter.value += 1;
}
```

## Accepted

```ds title="main.ds"
struct Counter {
    value: int32;
}

extension of Counter {
    increment(&exclusive this): void {
        this.value += 1;
    }
}
```

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