Live data from Hacker News

Pipelining might be my favorite programming language feature

herecomesthemoon.net

141–150 of 360 posts

Re: Pipelining might be my favorite programming language feature

#141
post #24

I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```

The pipe operator relies on the first argument being the subject of the operation. A lot of languages have the arguments in a different order, and OO languages sometimes use function chaining to get a similar result.

Re: Pipelining might be my favorite programming language feature

#142
post #24

I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```

We might be able to cross one more language off your wishlist soon, Javascript is on the way to getting a pipeline operator, the proposal is currently at Stage 2 https://github.com/tc39/proposal-pipeline-operator I'm very excited for it.

All of their examples are wordier than just function chaining and I worry they’ve lost the plot somewhere.

They list this as a con of F# (also Elixir) pipes:

    value |> x=> x.foo()
The insistence on an arrow function is pure hallucination

    value |> x.foo()
Should be perfectly achievable as it is in these other languages. What’s more, doing so removes all of the handwringing about await. And I’m frankly at a loss why you would want to put yield in the middle of one of these chains instead of after.

Re: Pipelining might be my favorite programming language feature

#144
post #143

Pipelining looks nice until you have to debug it. And exception handling is also very difficult, because that means to add forks into your pipelines. Pipelines are only good for programming the happy path.

At the risk of over generalized pronouncements, ease of debugging is usually down to how well-designed your tooling happens to be. Most of the time the framework/language does that for you, but it's not the only option.

And for exceptions, why not solve it in the data model, and reify failures? Push it further downstream, let your pipeline's nodes handle "monadic" result values.

Point being, it's always a tradeoff, but you can usually lessen the pain more than you think.

And that's without mentioning that a lot of "pipelining" is pure sugar over the same code we're already writing.

Re: Pipelining might be my favorite programming language feature

#145
post #109

This is just super basic functional programming. Seems like we're taking the long way around...

Have you read the article? This isn't about functional vs. imperative programming, it's (if anything) about two different ways to write functional code.

Keywords "super basic". You learn this in a "my first Haskell" tutorials. Seems tortured in whatever language that is though.

Re: Pipelining might be my favorite programming language feature

#146
post #112

The one thing that I don’t like about pipelining (whether using a pipe operator or method chaining), is that assigning the result to a variable goes in the wrong direction, so to speak. There should be an equivalent of the shell’s `>` for piping into a variable as the final step. Of course, if the variable is being declared at the same time, whatever the concrete syntax is would still require some getting used to, be…

Exists in R: Mydata %>% myfun -> myresult

Re: Pipelining might be my favorite programming language feature

#147
post #24

I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```

The pipe operator relies on the first argument being the subject of the operation. A lot of languages have the arguments in a different order, and OO languages sometimes use function chaining to get a similar result.

IIRC the usual workaround in Elixir involves be small lambda that rearranges things:

    "World"
    |> then(&concat("Hello ", &1))

I imagine a shorter syntax could someday be possible, where some special placeholder expression could be used, ex:

    "World"
    |> concat("Hello ", &1)
However that creates a new problem: If the implicit-first-argument form is still permitted (foo() instead of foo(&1)) then it becomes confusing which function-arity is being called. A human could easily fail to notice the absence or presence of the special placeholder on some lines, and invoke the wrong thing.

Re: Pipelining might be my favorite programming language feature

#148
post #24

I'm personally someone who advocates for languages to keep their feature set small and shoot to achieve a finished feature set quickly. However. I would be lying if I didn't secretly wish that all languages adopted the `|>` syntax from Elixir. ``` params |> Map.get("user") |> create_user() |> notify_admin() ```

Yes, a small feature set is important, and adding the functional-style pipe to languages that already have chaining with the dot seems to clutter up the design space. However, dot-chaining has the severe limitation that you can only pass to the first or "this" argument. Is there any language with a single feature that gives the best of both worlds?

[deleted]

Re: Pipelining might be my favorite programming language feature

#149

Earlier quoted context omitted.

Yes, a small feature set is important, and adding the functional-style pipe to languages that already have chaining with the dot seems to clutter up the design space. However, dot-chaining has the severe limitation that you can only pass to the first or "this" argument. Is there any language with a single feature that gives the best of both worlds?

FWIW you can pass to other arguments than first in this syntax ``` params |> Map.get("user") |> create_user() |> (&notify_admin("signup", &1)).() ``` or ``` params |> Map.get("user") |> create_user() |> (fn user -> notify_admin("signup", user) end).() ```

BTW, there's a convenience macro of Kernel.then/2 [0] which IMO looks a little cleaner:

    params
    |> Map.get("user")
    |> create_user()
    |> then(&notify_admin("signup", &1))

    params
    |> Map.get("user")
    |> create_user()
    |> then(fn user -> notify_admin("signup", user) end)

[0] https://hexdocs.pm/elixir/1.18.3/Kernel.html#then/2

Re: Pipelining might be my favorite programming language feature

#150
post #42

I always wondered how programming would be if we hadn't designed the assignment operator to be consistent with mathematics, and instead had it go LHS -> RHS, i.e. you perform the operation and then decide its destination, much like Unix pipes.

For function calls too? List the arguments then the function's name?
Post reply on HN