Reputation: 34884
What's a convention for using or ommitting parentheses when calling a function which accepts no parameters?
function1(aaa) |> function2() |> function3() |> function4(bbb)
# or
function1(aaa) |> function2 |> function3 |> function4(bbb)
Upvotes: 4
Views: 1931
Reputation: 121000
I believe, there is no convention on it yet.
Elixir
compiler warns about calling functions without parentheses outside of chains._
defmodule A do
def a, do: "¡Yay!"
def b1, do: IO.puts a
def b2 do
a = ":("
# 100 LOCs
IO.puts a
end
end
iex> A.b1
"¡Yay!"
iex> A.b2
":("
Credo
code analysis tool would report zero-arity function calls with parentheses by default.Elixir
code itself does not seem to use parentheses.In my humble opinion, the rule of thumb “use parentheses when calling functions” has very little advantages, and global suppressing of credo
’s guard does not worth it. I personally do not use them, unless it improves the readability. Hope it helps.
Upvotes: 4