Come on Elixir, if PHP can do it, anybody can - trailing comma now allowed in function & method calls


Who’s talking about syntax?
The visual arrangement will change and function arguments will go where function body is supposed to be.
I really don’t get it.
The arguments of a function are a single event.


To be honest, I wonder when git is smart enough to realize that when working with certain source code files, a line change that only adds a comma to the end is not that important. :stuck_out_tongue_winking_eye:


You are separating a sentence, basically a single ‘expression’, what this is talking about is when expressions-as-arguments are long enough that they no longer fit on one line, other-wise yes you would only use a single line. :wink:

It’s all exampled in this thread. :wink:

Yep yep, we need a Bikeshedding category/tag on these forums. ^.^

Then it’s not a perfect textual diff. ^.^


it’s arguably better if that single line of text has a lot of horizontal scrolling.

it’s the same idea with lists, and maps, etc.

sometimes you write them in a single line, and other times, you don;t


In my personal and inexperienced opinion, a function with 30 arguments is Ebola.
Please don’t encourage/facilitate people to write such functions.


Indeed long argument functions are painful, however a singular argument can be long in a set as well as it may not be a function but rather a macro thus the shape of the resultant AST needs to be kept intact.


I’m not sure I like macros either after trying to conditionally call a plug :confused:


It might not be that you have a lot of arguments, but that the arguments themselves are long. for example with pattern matching

def some_user_company_thing(%User{} = user, %Company{} = company, params \\ %{}) do

even just that starts getting long, imagine adding a guard

def some_user_company_thing(
  %User{} = user,
  %Company{} = company,
  params \\ %{},
) when something do
  # ¯\_(ツ)_/¯

maybe i’m weird but i prefer to see things like that than start horizontal scrolling in my code.

also, i don’t care a whole lot about the trailing comma, it’s helpful but not a huge pain point, it was mostly a tongue-in-cheek post, but we managed to get some discussion out of it :joy:


In my world, function arguments indicate only what the function accepts.
I would never manipulate data there, because that’s supposed to happen in the function body.
I feel that if manipulation happens in the function arguments, as well as in the function body, there’s now two places where bugs can happen.
Combined with SRP, my arguments never get long. ¯\ (ツ) /¯

def function_name(data1, data2 ,data3) do
"do stuff with data1,2,3"


Huh, this same issue got discussed on the ReasonML repo lately too, they gave a good reason (this is the owner of ReasonML speaking):

I’ve found that trailing commas help with a bit of paren-fatigue as well, because it helps you distinguish closing parens for arguments/tuples/variants from parens whose only purpose is to resolve precedence - at least in the case where things break onto multiple lines. It’s a small help, but it is a help.