Inconsistency or defined best practice (patterns for code blocks)

I am aware of the absence of a “pep”-like(1) guide for Elixir, however working my way through the book “Functional Web Development with Elixir, OTP, and Phoenix” I see different function block definitions without obvious (to me) reasons.

For example, page 114 - chapter 5 - defines a GameSupervisor module that implements a few functions, two of which are sampled below;

def start_game(name), do:
  Supervisor.start_child(__MODULE__, [name])

def stop_game(name) do
  Supervisor.terminate_child(__MODULE__, pid_from_name(name))

Is this the author random picking do/end over do: or is there some, perhaps undocumented, rule of thumb?

Also, while questioning style guidance, is there any belief over function grouping, e.g. is it best practice to cluster private and normal functions that relate together (in a particular order?) or is there some other kind of sorting preference?


(1) Python Enhancement Proposal

No rule per se. If you feel a function is a one line code, then go for the do: approach.

I personally never make do: functions unless after mix format they are still one line. If the formatter makes them two lines – like start_game in your case – I’ll just convert them to the do / end format.

If there’s any rule of thumb at all, it’s not specific to Elixir: make your code readable and quick to scan and understand.