Onor.io
Just wondering about opinions on how to format code where I’m capturing the result of a few pipelined operations. For example:
v =
op1
|> op2
|> op3
I’m inclined to put the variable the result is going into up on a line by itself so it’s more obvious that the whole thing is getting captured to a variable. But I’d like to hear the opinions of others regarding how I might handle this.
BTW, Could someone create a “coding-style” or “coding-standards” tag and attach it to this message? I don’t have sufficient privileges to create new tags.
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
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
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
sashaafm
I usually do
v = op1
|> op2
|> op3
This leads the code to be condensed, explicit and easy to read. I’ve also seen this way a lot in a lot of Elixir code.
EDIT: I’ve created the tag ‘coding-standards’
sztosz
https://github.com/niftyn8/elixir_style_guide
Qqwy
I really like the indented style of
When you don’t indent there, it is less clear that the pipeline will still end up affecting the value to the left of the equals-sign.
Indentation in Elixir usually don’t matters for execution, but it does significantly affect the readability.
Onor.io
And readability is what I’m most concerned about.
Onor.io
Thanks for that link. I had a link to a different Elixir Style guide as well. I’m asking partially because I’d like to hear if there are points for and points against that style. It strikes me as good coding style but if there’s some strong reason not to use it, I figure the folks here would be most likely to know it.
sashaafm
I honestly prefer the way I described mainly because the code is written with a “block shape”. I find it way easier on the eyes and provided better readability. When skimming over code catching these code blocks from “the corner of your eye” seems to make it easier to remember and associate what the code block does as well. Just my opinion, of course.
Yesterday I actually found that the following piece of code works:
but I couldn’t find an actual style I enjoyed for it. In these cases I prefer to not use syntactic sugar and shortcuts in order to keep the code in more standard and popular ways of styling.
Onor.io
That’s very interesting @sashaafm. I didn’t realize that sort of code would work.
Qqwy
Interesting that this works. It is a great example of how Elixir is very regular in the syntax it provides (what I mean by that, is that there are nearly now ‘exceptions’ to when certain syntax is possible).
Of course, in the example above, readability is probably improved by extracting the case-statement to its own function.
riverrun
You can also use the pipe after the case statement.

Here’s an example which includes concatenating the string before sending it to url_decode64 function:
defp urldec64(data) do data <> case rem(byte_size(data), 4) do 2 -> "==" 3 -> "=" _ -> "" end |> url_decode64! endNow I think that’s really expressive and easy to read. Having said that, I don’t know how many people will agree with me