by dnautics · 5y ago · 0 comments
In action: https://youtu.be/WMYc3VzOSpg&t=23m20s
I suppose the problem with this snippet is that it keeps you from using more powerful tools like tracer and recon.
Their power, as you point it, is in the ability to jump into any statement and add another action with minimal syntax. It's extremely useful while iterating on development because you can quickly check that something works (or check on what is happening).
This is good and readable:
nuclear_missile
|> open_hatch()
|> open_fuel_lines()
|> fire_thrusters(:all)
|> configure_gps(%Coordinates{...})
This is unnecessary: word_count =
words
|> Enum.count()
This is better: word_count = Enum.count(words)
Pipes read like a list of bullet points. We can easily deal with up to a dozen bullet points, but a single bullet point is bad grammar style.Plus think of how much easier that pipe makes it for you to understand what is going on.
[1] https://github.com/RodrigoLeiteF/craftup/blob/main/backend/l...
The Elixir implementation inverts the classical order of piping last in functional languages to the detriment of it. IMO a language should either support pipe last AND currying by default or supply a multitude of thread operators like Clojure does (->, ->>, as->, etc). Elixir's is just middle-of-the-road-weird.
Clojure is way more consistent in this regard:
- thread first (->) when operating on maps.
- thread last (->>) when operating on sequences.
- as-> "choose your own adventure".The only place where pipe order bristles is Enum.reduce, but I'd bet if I counted I'd have wanted it the normal way more often than the backwards way.
I wished Elixir would’ve used “io” instead of “IO”.