Papillon6814
Do you use formatter in your elixir project?
Hi! I’m wondering if I should use formatter of elixir. I have never used any formatters in past projects.
So do you use formatter? And why do you use it?
Most Liked
dimitarvp
Why not go all the way?
Have that in your aliases section of mix.exs:
check: [
"compile --warnings-as-errors",
"format --check-formatted",
"credo --strict",
"coveralls.html",
"dialyzer --format short"
]
Then just run mix check and voila, you almost have locally running CI.
dimitarvp
For my Elixir, Rust, JavaScript, JSON and OCaml editing I use formatters even if I don’t like all of their decisions how things should look like.
Truth is, our code will be read by other people so I prefer to be a good citizen.
John-Goff
I love using the formatter, and specifically format on save in my editor, because it allows me to see if my code is right as it happens. If I save my file and everything snaps into place, I know I did things right. If it doesn’t, I know that I have a syntax error somewhere in the code I just wrote. Saves me from flicking back and forth to the server and my editor.
Sebb
I love tabular code.
This
defp decode(addr_t(:ind), _dest, data) do
case data do
<<0::6, data::bits>> -> {:t_data_ind, nil, data}
<<0b01::2, seq::4, data::bits>> -> {:t_data_con, seq, data}
<<0b1000_0000::8>> -> {:t_connect, nil, <<>>}
<<0b1000_0001::8>> -> {:t_discon, nil, <<>>}
<<0b11::2, seq::4, 0b10::2>> -> {:t_ack, seq, <<>>}
<<0b11::2, seq::4, 0b11::2>> -> {:t_nak, seq, <<>>}
_ -> {:error, :invalid_tpci}
end
end
for me, is just way more readable than
defp decode(addr_t(:ind), _dest, data) do
case data do
<<0::6, data::bits>> -> {:t_data_ind, nil, data}
<<0b01::2, seq::4, data::bits>> -> {:t_data_con, seq, data}
<<0b1000_0000::8>> -> {:t_connect, nil, <<>>}
<<0b1000_0001::8>> -> {:t_discon, nil, <<>>}
<<0b11::2, seq::4, 0b10::2>> -> {:t_ack, seq, <<>>}
<<0b11::2, seq::4, 0b11::2>> -> {:t_nak, seq, <<>>}
_ -> {:error, :invalid_tpci}
end
end
but I know, that most people don’t like it, so it will never be possible to format Elixir-code like that. And that is a good thing. It’s important to have a common code style everyone can read. So I keep formatting my C files in crazy ways, because in C, everybody complains about your style anyway and there will never be any agreement.
OvermindDL1
I still use the formatter even though I really really hate some of the things it does (like no trailing comma’s on multi-line things) just for consistency with what everyone else expects. I do the same with rust’s formatter and C++ formatting via clang and others as well. I may do some slight tweaks in configs (hard tabs instead of spaces because screw 3+width indentations when I’m in a terminal) when possible, but otherwise try to keep it as ‘vanilla’ as I can. It makes it easier for other people to look at and PR to your code.







