Crowdhailer
Creator of Raxx
I’ve been hearing much about the new formatter and it’s something I have been keen to try.
I find examples buy far the most illuminating way to try some new tech. To that end I though I would blindly run the new formatter on my largest open source Elixir code base, Ace.
I did no preparation before hand and in one swoop was able to format the whole project using
$ mix format mix.exs "lib/**/*.{ex,exs}" "test/**/*.{ex,exs}"
Results
- My project is now larger. 1369 lines added but only 752 removed.
A lot of these are empty lines. Every case clause is separated by a new line and so is every function head.
It looks like my personal convention of separating different functions but not different function heads of one function is now over - Brackets are now applied automatically so no more dealing with those warnings. This is a big win.
- Numbers lose underscores
65_535→65535
- Several cases where things are now indented to line up with something above rather than just two spaces, this is probably what I am least happy about but I can get over it for the consistency
- Comments now always end up on a separate line.
In conclusion I think that is a great additions and I hope that the numbers will eventually be formatted with the underscores
Trending in Discussions
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
Hi there! :wave:
@frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with.
But I don’t use it anymore.
Serverless was the promis...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog
It says that Fly is going all-in on sprites, which is a worry ...
New
This was an interesting post by Jose. Curious to hear what others think. Evolving programming languages in the AI era - Dashbit Blog
Gen...
New
In my third year of college, around 2010, I found Erlang. A few years later, I found Elixir. I liked the ideas at once: many small proces...
New
Other Trending Topics
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
In 2021 I started a new library called Tempo with the objective of modelling time as a set of intervals - not as instants. In 2022 I gave...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
krapans
I agree with this point because I use a lot this kind of number format all over the project.
Gyllsdorff
I this the library you used?
I hope this is a bug.
krapans
No, as far as I understood, he used
mix formatwhich is available in Elixir 1.6Crowdhailer
Yes I installed the latest version of Elixir from master.
It’s nice because I am running my project on 1.5, i.e. stable, in a docker container but having 1.6 on my machine means that when editing that project atom is using 1.6 to provide formatting.
Gyllsdorff
Oh, so it is this one in the main Elixir repo. Nice, next release will certainly be interesting.
It seems to have the code for inserting underscores in integers if the number of digits are
>= 6. I wonder if we can change that to>= 4.https://github.com/elixir-lang/elixir/blob/425cebf10c24193f42187664dae6aaa8dbe4486f/lib/elixir/lib/code/formatter.ex#L1352-L1363
NobbZ
Please don’t… I was born 1981, not 1_981…
Gyllsdorff
And our http-port number is
20_693, not20693, sometimes the format depends on the context and not on the data type.That’s kind of what I meant when I said:
It will be impossible to satisfy everyone. But I agree,
>= 4might be too short.AstonJ
Looks good
I would have normally done this:
And the formatter does this:
Which, looking at it now, is far more readable
Crowdhailer
Well I also have several pieces of code which have prices
120_00.tmbb
For what it’s worth, my opinion on the changes. It’s mostly negative (warning, 100% subjective unless marked):
I like this convention too. Keeps together functions heads that belong to the same function, which directs my eyes to logical groups of clauses. But the new output doesn’t shock me, except for the problem of taking more space.
Like @AstonJ said above, this might increase readability a little, I don’t know. But it does take away more vertical screen space for sure, which is a bad thing. I’m not sure whether the negatives outweigh the positives here. The question of taking up more space is the only “objective” argument I want to bring to the table. Maybe the trade-off is worth it, and maybe it isn’t but wasting valuable vertical screen space is not just a matter of personal preference
No opinion on this one. Brackets or no brackets, any choice would be ok.
Please don’t… This is one of those places where the programmer’s intent is expressed through formatting. Sometimes,
12_000is more readable than12000, sometimes it’s the opposite. I think this should be left up to the programmer. Sometimes you want1200, sometimes you may want1_200and sometimes12_00(value in cents, or something like that).Or is it one of the goals of the formatter to make sure that two blocks of code that compile to the same AST (module line numbers) will always produce the same output? If this is a goal to aim for, then I think I can accept the disruption of the underscores.
This takes up more valuable screen space for very little benefit, I think. What’s the reasoning behind this rule?
There are some obvious improvements in the source that @Crowdhailer didn’t bother to mention, like minor whitespace issues, and for those things the formatter is great.
My main argument against this might be a vague personal distaste against prescriptive code formatters: everybody prefers to edit text instead of AST nodes directly, but then we make all this effort to make the code as uniform as possible to preserve consistency. It’s almost as if we should have been writing AST nodes all along? Or Lisp? You don’t get many discussions on how to format that…
Finally, despite what I’ve said above, having a code formatter is pretty cool, especially if it can convert from AST to code, because it opens up exciting possibilities for code transformation tools that are aware of the AST. This can be useful for project generators, because it would make it easier to add code to the middle of a module and even for refactoring tools. It would make changing a module name over the whole code base almost trivial, for example: It could just compile the modules, replace the appropriate alias and write the changes to disk. It might have some corner cases I’m not aware of, but it would certainly make this kind of thing much easier. It would produce nice diffs, of course, because the code would have been formatted already. For renaming a function it wouldn’t go as well:
or even worse:
but with the help of
mix xrefor even access to the elixir manifests or the erlang core output it might make a passable job. I hope the formatter will be made available as a standalone tool that can be used on the AST for these purposes.Having a code formatter that is well tested and guarantees it’ll keep the semantic meaning of the code is much better than not having one, no matter how much I disagree with the space-wasting “features”.