rvirding
Creator of Erlang
This is a beauty. Seen in the wild, not from me or my colleagues.
interval
|> Kernel.-(time_elapsed)
|> max(0)
|> schedule_events()
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
Hi there,
I’m in the process of deploying a Phoenix app to a EU host (UpCloud specifically), where the instances provided are mostly raw...
New
Other Trending Topics
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
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
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
- #performance










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
alco
It is much harder to grasp than
peerreynders
Given many developers proclivity towards inline functions (of any size) I suspect that in a “pipeless” environment
would have been the likely result (which I find less clear (harder to parse) than the two line version).
jeremyjh
I agree that Alco’s forumulation is best, but for short phrases its idiomatic to avoid unnecessary assignment, and pipes are the best way to do that in many cases.
More readable than the nested calls is:
Which, seems fine to me, but Credo will give me **** about not starting a pipe with a value so I have to write
I don’t think that’s much better than what we started with.
peerreynders
Unnecessary from what perspective?
Sure the computer doesn’t need it but:
p. 15, Refactoring: Improving the design of existing code; 1999
The right hand side of the assignment focuses on what needs to be done - the left hand side enlightens us why it’s being done.
Sometimes I wonder whether these “idioms” date back to when this was normal
That
zis unnecessary.Pipes can be similarly affected by bad or lack of naming which is what is really going on in the OP.
which should really become
but even that seems forced compared to
jeremyjh
Unnecessary from the programmer’s perspective, of course. In some cases it’s necessary to make code understandable, but it isn’t always of course - that’s why the operator exists.
josevalim
I wouldn’t say the operator is to avoid assignment. The operator is to simplify nested calls.
jeremyjh
Isn’t nesting a means to avoid assignment? At least, assignment is the other alternative to nesting.
rvirding
One issue (problem) with the pipe is that in one way it hides what you are doing. Yes, you can see the actual operations being done but it can also hide what the actual data along the way is. Yes, you can add comments. However, using assignments means that you automatically do get information about what the actual data along the way is (at least if you use reasonable variable names).
I am not saying that you should avoid pipes and always use assignments, but I do think you can go too far with long pipe sequences.
This gets back to what I think is a very important question: for whom and why are you writing this code? Is it a quick hack which you don’t expect to have a long life? If it is for a product you envisage to be in use a long time which other people will maintain and develop then it is very important that you write clear, easily understandable and very explicit code. In this case maybe using judiciously using assignments can be a Good Thing™. I try to ask myself “in six months time will I understand what i have done here?” [*]
What I was really poking fun at was how far they had gone with the
Kernel.-to be available to use a pipe.[*] This also explains my opinion on having too many implicit default values which I can vent in a later post.
sribe
Another point to consider: pipelines are quite clear when a new version of the same thing is being passed along to each function, but when the context of what is being passed changes midway through, that makes it hard to read. A Plug.Conn being passed through adding headers, setting status, body, sending, etc is the perfect example of a good use.
In your example, even though it’s a number being passed, what that number represents is different at each stage. And the fact that
foo |> Kernel.-(bar)is vastly less clear thanfoo - barmeans you’re starting off the pipeline with the very first step obscuring rather than clarifying.yurko
That’s a good point, just recently in a test I moved the ending of the pipe into a separate call cause it made it unclear as to what the input is, so the whole test looked confusing despite the nice looking pipeline
I still think the pipes are awesome, but they definitely can be abused.