# Function parameter

**URL:** <https://ziggit.dev/t/function-parameter/17756>\
**Category:** Explain\
**Created:** [September 30, 2026, 4:30am UTC](https://ziggit.dev/t/function-parameter/17756 "2026-09-30T04:30:22Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [September 30, 2026, 4:30am UTC](https://ziggit.dev/t/function-parameter/17756/1 "2026-09-30T04:30:22Z")

</div>

Edit: makes original post as a question.

I want to know when a method needs to take the outer type as first parameter? Take the common `Iterator` as example: A `next()` method of type `Iterator` usually takes the type it lives in as first parameter and you don’t have to fill in as argument at call site; an `init()` method of type `Iterator` doesn’t care about that. E.g., `next(it: *Iterator) ?u8` and `init(vector: []const u8) Iteratior`

---

<div class="post-metadata">

**Author:** ![vulpesx](https://ziggit.dev/user_avatar/ziggit.dev/vulpesx/32/3989_2.png) [@vulpesx](https://ziggit.dev/u/vulpesx)\
**Post date:** [September 30, 2026, 4:41am UTC](https://ziggit.dev/t/function-parameter/17756/2 "2026-09-30T04:41:51Z")

</div>

You’ve only described a feature, what about it do you want explained.

---

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [September 30, 2026, 4:44am UTC](https://ziggit.dev/t/function-parameter/17756/3 "2026-09-30T04:44:10Z")

</div>

I’ve seen lots of methods take the outer type as its first parameter. I don’t know when to do that.

---

<div class="post-metadata">

**Author:** ![Nae](https://ziggit.dev/user_avatar/ziggit.dev/nae/32/10157_2.png) [@Nae](https://ziggit.dev/u/Nae)\
**Post date:** [September 30, 2026, 5:21am UTC](https://ziggit.dev/t/function-parameter/17756/4 "2026-09-30T05:21:11Z")

</div>

It’s not centralized in the langref, but maybe you’re looking for the [dot syntax](https://ziglang.org/documentation/0.16.0/#struct)? More precisely in the the context of struct.

This is a syntactic sugar, there are only function and function call, it’s just presented differently.

* * *

The pattern of the iterator is closely related to [while loop with optionals](https://ziglang.org/documentation/0.16.0/#while-with-Optionals), so maybe your question is about that.

This is kind of emerging from the interaction of while, captures and optionals

---

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [September 30, 2026, 5:56am UTC](https://ziggit.dev/t/function-parameter/17756/5 "2026-09-30T05:56:22Z")

</div>

So it’s syntax sugar like `Iterator.next(*Iterator)` V.S. `iter.next()`. I got it.

---

<div class="post-metadata">

**Author:** ![Salmon](https://ziggit.dev/user_avatar/ziggit.dev/salmon/32/10236_2.png) [@Salmon](https://ziggit.dev/u/Salmon)\
**Post date:** [September 30, 2026, 6:03am UTC](https://ziggit.dev/t/function-parameter/17756/6 "2026-09-30T06:03:08Z")

</div>

Is there some Zig idiomatic way for naming the first argument? In Python `self` is the convention in methods, but what is good practice in Zig?

---

<div class="post-metadata">

**Author:** ![zeeqeeng](https://ziggit.dev/letter_avatar_proxy/v4/letter/z/8baadc/32.png) [@zeeqeeng](https://ziggit.dev/u/zeeqeeng)\
**Post date:** [September 30, 2026, 6:24am UTC](https://ziggit.dev/t/function-parameter/17756/7 "2026-09-30T06:24:16Z")

</div>

I found there are two patterns: 1) `doThing(self: @This())` 2) `doAnotherThing(self: Self)` with `const Self = @This();` As for return type, maybe `Self`, maybe `MyType` though `self: Self` or `self: @This()` used.

---

<div class="post-metadata">

**Author:** ![biom4st3r](https://ziggit.dev/user_avatar/ziggit.dev/biom4st3r/32/4342_2.png) [@biom4st3r](https://ziggit.dev/u/biom4st3r)\
**Post date:** [September 30, 2026, 6:25am UTC](https://ziggit.dev/t/function-parameter/17756/8 "2026-09-30T06:25:45Z")

</div>

Some people just use self. I’ve seen it advocated, and I agree, to name it something meaningful instead. For example if i’m in a function `pub fn explode(self: Player)` self isn’t very descriptive and I find it more useful to provide the context `I'm acting on a player`, than `I'm acting on whatever the current self object is`

So I’d prefer `pub fn explode(player: Player)` or something that provides more information

---

<div class="post-metadata">

**Author:** ![Salmon](https://ziggit.dev/user_avatar/ziggit.dev/salmon/32/10236_2.png) [@Salmon](https://ziggit.dev/u/Salmon)\
**Post date:** [September 30, 2026, 8:20am UTC](https://ziggit.dev/t/function-parameter/17756/9 "2026-09-30T08:20:44Z")

</div>

Interesting, that’s also what I’ve been doing in my project. Precisely for the reason you brought up. Glad to see I’m not alone 🙂

---

<div class="post-metadata">

**Author:** ![gwenzek](https://ziggit.dev/user_avatar/ziggit.dev/gwenzek/32/8137_2.png) [@gwenzek](https://ziggit.dev/u/gwenzek)\
**Post date:** [September 30, 2026, 8:34am UTC](https://ziggit.dev/t/function-parameter/17756/10 "2026-09-30T08:34:20Z")

</div>

personally I’ve come back from the `self: Self` pattern.  
First it’s uninformative, if you jump in the middle of a big file and you just see `self: Self` it’s not helpful. Am I looking at the manager or unmanaged version of the hashmap ?

Second it doesn’t play well with nesting, if you nest your struct the nested one can’t use `Self` again

---

<div class="post-metadata">

**Author:** ![pierrelgol](https://ziggit.dev/user_avatar/ziggit.dev/pierrelgol/32/10233_2.png) [@pierrelgol](https://ziggit.dev/u/pierrelgol)\
**Post date:** [September 30, 2026, 8:58am UTC](https://ziggit.dev/t/function-parameter/17756/11 "2026-09-30T08:58:41Z")

</div>

Agree, I personally prefer to name things like

```zig
pub const Sensor = struct {
    pub fn doStuff(camera: *Sensor) void {
        _ = camera;
    }
};

```

and if i don’t make something an implicit struct type, I love to do this

```zig
pub const Sensor = struct {
    pub fn doStuff(camera: *hardware.Sensor) void {
        _ = camera;
    }
};

```

basically even in the same file use a 2 level namespace, this way it’s really easy to find where something is coming from

---

<div class="post-metadata">

**Author:** ![Chaz](https://ziggit.dev/letter_avatar_proxy/v4/letter/c/4491bb/32.png) [@Chaz](https://ziggit.dev/u/Chaz)\
**Post date:** [September 30, 2026, 5:05pm UTC](https://ziggit.dev/t/function-parameter/17756/12 "2026-09-30T17:05:34Z")

</div>

Agreed, I only fall back to the name ‘self’ when it’s paired with a type ‘@This()’ and even then there is often a better name.

---

<div class="post-metadata">

**Author:** ![nonzeroq](https://ziggit.dev/user_avatar/ziggit.dev/nonzeroq/32/9106_2.png) [@nonzeroq](https://ziggit.dev/u/nonzeroq)\
**Post date:** [September 30, 2026, 5:27pm UTC](https://ziggit.dev/t/function-parameter/17756/13 "2026-09-30T17:27:58Z")

</div>

I tend to spell out types using their fully qualified name w.r.t to the outermost scope, especially when the type name is something rather uninformative on its own, and only makes sense when coupled to the owning type, eg

```zig
const Node = struct {
    fn do_something(node: Node) void { 
        // ...
    }
    const Index = enum(u16) {
        _,
    
        fn get(index: Node.Index, list: []const Node) Node {
            // ...
        }
    };
};

```

I reserve the use of `const Self = @This()` for templated types, because due to Zig’s ability to nest types and methods, seeing a wild `Self` or `@This()` is absolutely unhelpful, and I don’t like to strain my eyes counting levels of indentations. Generic types are the only exception, because I often give the type function the name I want to give the type, and you can’t shadow names.

Incidentally, as this is a problem I rarely encounter in other languages, this has forced to think a lot more about the names I give types.
