# Args in gen\_\*:init/1

**URL:** <https://erlangforums.com/t/args-in-gen-init-1/3169>\
**Category:** Questions / Help\
**Tags:** stdlib\
**Created:** [January 9, 2024, 5:40am UTC](https://erlangforums.com/t/args-in-gen-init-1/3169 "2024-01-09T05:40:15Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![elbrujohalcon](https://erlangforums.com/user_avatar/erlangforums.com/elbrujohalcon/32/241_2.png) [@elbrujohalcon](https://erlangforums.com/u/elbrujohalcon)\
**Post date:** [January 9, 2024, 10:03am UTC](https://erlangforums.com/t/args-in-gen-init-1/3169/5 "2024-01-09T10:03:12Z")

</div>

This is **exactly** why I have the exact opposite rule as @vances’ one:

> Never use lists in the `Args`/`InitArgs` parameter for `gen_*:start[_link](…)` / `init/1`.

The [erlang docs](https://www.erlang.org/doc/design_principles/gen_server_concepts) provide an example that includes…

```erlang
start_link() ->
    gen_server:start_link({local, ch3}, ch3, [], []).

```

…and…

```erlang
init(_Args) ->
    {ok, channels()}.

```

And I think that example, and other similar pieces of documentation, are misleading at best. Mainly for two reasons:

1. Using an empty list if you don’t need to pass anything to `init/1` may lead people to believe that you’re passing 0 arguments to the `init` function (because sometimes arguments are passed down to some functions like `supervisor:start_child/2` as lists. But that’s not true. With an empty list, you’re passing a single argument to `init/1`, as usual. It’s just that in this case it’s a list. If you don’t need to pass any external values down to `init/1`, I recommend the usage of an empty map (`#{}`), an empty tuple (`{}`), the atom `undefined`, or something even more explicit, like the atom `no_arguments`.
2. Calling the single parameter of `init/1` `Args`. It’s not wrong, but again it may lead people to believe that since it’s written in plural, it _has_ to be a list of arguments. When in reality it’s a single argument.

Using this example code to build servers has led more people than I count to write stuff like this…

```erlang
-module my_server.
% …exports and everything else…
start_link(AParam) ->
  gen_server:start_link(?MODULE, [AParam], []).

init(AParam) ->
  …

```

Which is a code that compiles and it then fails mysteriously when it’s executed. It has produced many headaches over the years since that example was written.

---

_[View the full topic](https://erlangforums.com/t/args-in-gen-init-1/3169)._
