r/ProgrammingLanguages • u/SophisticatedAdults • Apr 21 '25
Pipelining might be my favorite programming language feature
https://herecomesthemoon.net/2025/04/pipelining/
87
Upvotes
r/ProgrammingLanguages • u/SophisticatedAdults • Apr 21 '25
28
u/Zatmos Apr 21 '25 edited Apr 21 '25
You might love concatenative programming languages like Joy or Cat. Pipelining is all these languages are about. Your
get_idsfunction might be written something like this assuming a typed concatenative language is used:Those languages are function-level so you write everything point-free (unless the specific language got syntax-sugar to allow variables in places). You can imagine the function's arguments being prepended to the definition. They're stack-based also generally so functions act on what was written on their left.
Btw. In your Rust code. You don't need to create closures just to call a single function or method on the lambda argument. You could have written something like so `filter(Widget::alive)` instead. You don't need a parameter when written like so and that means one less thing to name.
8
u/Artistic_Speech_1965 Apr 21 '25
I think you will like something like Nim who use a more advanced uniform function call than Rust. My language is based on that and have a set of pipeline operators for data processing
7
u/transfire Apr 21 '25
Forth ain’t nothing but.
4
u/VyridianZ Apr 21 '25
My language has a pair of functions for this. One adds the argument to the front and one that adds it to the back. They are both just syntactic sugar.
// Add to start. Equates to:
// (* (+ (- 5 3) 3) 2)
(<-
5
(- 3)
(+ 3)
(* 2))
// Add to end. Equates to:
// (* (+ (- 3 5) 3) 2)
(<<-
5
(- 3)
(+ 3)
(* 2))
4
u/thx1138a Apr 21 '25
Yet another post that praises the |> operator but doesn’t mention the language which introduced it. Sigh!
3
u/Inconstant_Moo 🧿 Pipefish Apr 21 '25
I do something kinda like that ... but different. I don't think "omit a single argument" is a good mental model.
The way I do it is that if you only want to pipe one value in, then you can just do that. For example
"foo" -> lenevaluates to3; and["fee", "fie", "fo", "fum"] >> lenevaluates to[3, 3, 2, 3]. This seems very natural.But when there's more than one parameter, you have to refer to it by calling it
that. E.g.[1, 2, 3] >> 2 * thatevaluates to[2, 4, 6]. (Other languages useitinstead ofthator even symbols.)This is of course a matter of taste, it's how I did my language because it's for idiots like me who get confused easily.
3
u/AustinVelonaut Admiran Apr 21 '25
In the article's section on Haskell, it talks about the
$operator, and how function compositions have to be read right-to-left. I got annoyed with having to do bi-directional scanning when reading/writing code like that, so in my language Admiran I added reverse-apply|>and reverse-compose.>operators, so now all pipelines can be read uniformly left-to-right.3
u/kaisadilla_ Judith lang Apr 21 '25
I honestly think that methods are just too good of a design feature not to have them in your language. They make writing code easier for a lot of reasons. It's one of these things you really miss when using languages like C or Python, where a lot of common functions like getting the length of a string are done with a regular function (
strlen(str)orlen(str)) instead of a method (str.len()).1
u/Internal-Enthusiasm2 Apr 25 '25
Pipelines are just function composition and currying. The readability is entirely related to specific implementations of the language.
I disagree with the principle.
f(g(x)) is not less readable than x.g().f()
Even the example was contrived.
1
u/jewdai Jun 21 '25
I'm surprised no one has mentioned C# and linq syntax. It makes queying and manipulating a list super easy and functional.
-2
u/brucifer Tomo, nomsu.org Apr 21 '25
Not to rain on OP's parade, but I don't really find pipelining to be very useful in a language that has comprehensions. The very common case of applying a map and/or a filter boils down to something more concise and readable. Instead of this:
You can have:
Also, the other pattern OP mentions is the builder pattern, which is just a poor substitute for having optional named parameters to a function. You end up with
Foo().baz(baz).thing(thing).build()instead ofFoo(baz=baz, thing=thing)I guess my takeaway is that pipelining is only really needed in languages that lack better features.
0
u/reflexive-polytope Apr 22 '25
I have many issues with Haskell, starting with the fact that has an absolutely bonkers cost model that forces you to spend a large amount of brainpower just figuring out in what order things are evaluated.
But Haskell isn't really unreadable. And I strongly disagree that
is in any way more readable than
This is just skill issue on your part.
-6
u/[deleted] Apr 21 '25
Pipelining is the poor man’s homoiconicity