Pipeline-Oriented Programming [video]
youtube.com
youtube.com
We just recently started looking at using EFCore (instead of raw SQL via Dapper) and it is dawning on me that it was a strategic mistake to not further utilize the leverage that expressions can bring to the party.
[1] https://github.com/louthy/language-ext
[2] https://louthy.github.io/language-ext/LanguageExt.Core/Effec...
[3] https://github.com/louthy/language-ext/blob/main/Samples/Eff...
Github's client-side rendering "enhancements" strike again. Maybe I'll submit another cranky support ticket this weekend...
Not as much of this applies to LINQ as we'd all wish. If you've got LINQ in a performance hotspot, the first thing to do is remove the LINQ. I love LINQ but plainly written loops are faster every time, and removing LINQ from profiled hotspots has always been a successful optimization for me in practice. Avoid it in performance hotspots. Once you've removed the LINQ, eliminate any inner-loop heap allocations and you're probably done optimizing. LINQ and heap allocation are the two major killers of performance in typical C# code.
It feels, at worst, like the height of arrogance to assign new terms to existing concepts, as though you've just invented the concept. And, at best, a form of anti-intellectualism - to try and make functional concepts accessible to ex-OO devs. But it feels to me like all it does is muddy the waters.
Not everything needs to be oriented programming.
Or, probably more often, a new term for the same old thing is not better, serves no useful purpose, and just confuses.
But yeah, it was weird hearing about this "new" idea I've been using for 30 years.
I worry that lazy evaluation will wind up as "filter based programming" next year.
But if it puts it in a form python or c# programmers can readily consume, it's probably okay.
Also nice to see someone doing something with f#.
While I tend to agree with your critique I also appreciate that a different lens can be more accessible or less held back by historical baggage.
I always struggled with fundamental terminology used in this family of languages, particularly lambda. Lambda as a term does carry historical baggage. The term wasn’t picked out of thin air. And casually looking at Lisp and Scheme code, if you don’t know that baggage, lambda is (at least to me) an opaque term.
But I luckily stumbled upon a book “Simply Scheme”. And the first thing they did was redefine a bunch of terms. No more CAR, CDR, CADR. Instead you got things like FIRST, REST. SECOND. Importantly, they redefined LAMBDA to FUNCTION.
Well, Shazam. Ding, ding, ding. This was an “aha” moment for me. Boy did a lot of stuff suddenly fell into place.
So, simplifying the vocabulary can be very helpful for introducing gateway concepts.
[It is very 'branding' and a disservice to not to mention the popular terms.]
I do see them all as the style I think and write in.
Hilariously I’ve done exactly that for the exact opposite reason.
I have in the past “come up” with a programming paradigm that perfectly satisfied a need and when I went to tune it up for general use I realized it was similar to a concept I was unfamiliar with, or struggled to grasp previously or previously hated working with in the manner it was taught or interfaced.
~”This looks like a monad, maybe I’ll call this a monad, but I’m unsure what precisely is the mathematical proof supporting, or what the limits and boundaries of the concept of a monad are so to avoid someone mocking me saying ‘this is the worst monad implementation, it’s hardly even a monad, it’s like a low effort subset of what a monad is.’ I’ll just name it something else.”
This is an uncharitable viewpoint. Bringing FP concepts to more devs is a good thing. I don't see how teaching better ways is any form of anti-intellectualism.
It's treating OO programmers, who are curious about FP, as though they can't handle anything unless it's got "oriented programming" after it. In my mind that's a form of anti-intellectualism.
I really don't buy that it's needed at all. And I feel I'm in a pretty good place to state that, language-ext has ~6K stars on GitHub and the package has been downloaded nearly 13 million times [2]. It shows that devs that use an OO-first language can and are able to learn FP terminology. I never pandered and I get many OO devs coming to the library. Yeah, sometimes they need some guidance, but I've never needed to invented new terminology.
OO engineers are just as smart as FP engineers, they've just worked in different paradigms and need to learn the lingo when switching - the sooner they do it the better able they are to communicate with others in the FP community.
It's not a renaming. Pipelines have been a thing in software for ages. Correlating differing (surface) systems to each other is very useful when it turns out that they're expressing the same "thing" but in different manners.
That's because most programmers ignore you as soon as they hear the m-word (or Haskell), as all that useless in "the real world"(TM).
Every so often on hacker news you get some article like this that tries to introduce a "new concept" that they didn't know has already existed for the longest time or you get some other person writing a blog post about some programming analogy how programming is like "theory building". I just roll my eyes. I really wonder why you only see programmers who like to think of themselves as "highly intelligent" and calling what they're doing "theory building" and why civil engineers or electrical engineers don't supply this endless vault of "analogy blog posts" for HN readers to self pleasure themselves to.
Well, in one sense, nobody ever writes a general program - they only write specific ones.
But if your claim is "most things most people do during the day could be pipelined", I'd like to see your supporting evidence, because I'm not at all sure that claim is true.
For example, as far as I understand, GUIs are very hard to pipeline. How much of the programming done in the average day is on GUIs?
I believe it is, but of course it's hard to prove; I have my own libs in whatever language I use which are piping libraries very much inspired by FP, LINQ, Haskell, APL/k and other such things. And most things I do, do fit. But yeah; how to show that; I can translate most things we write anyway. We write SaaS in the broadest sense.
> For example, as far as I understand, GUIs are very hard to pipeline.
Are they? Aren't we pulling data in reducers, transforming it to structures that can be shown in the templates and transforming again on input/click and sending somewhere?
It's all pipes, kind of. Sure, some things are not, but those things at least we don't encounter very often. And when they are pipes, other ways of processing are just plainly worse in every way imho.
There are no imperative programmers, who are interested in FP - but won't switch to it because they'd have to give up their pragmatic getCallStack() and setCallStack() methods.
(
range(10)
| Map(lambda x: x * 10)
| Filter(lambda x: x % 2 == 0)
| Reduce(lambda a, b: a + b)
)
and more. https://tandav.github.io/pipe21/most operators are basically oneliners: https://github.com/tandav/pipe21/blob/master/pipe21.py#L17
I also maintain a list of libraries which uses pipeline/chain syntax: https://tandav.github.io/pipe21/similar-tools/
also, have you seen lazyjs? Also very cool.
https://programming.dev/comment/6718327
Here's a bit:
: add1 ( x -- x' ) 1 + ;
: square ( x -- x' ) dup * ;
: double ( x -- x' ) 2 * ;
: demo1 ( -- n )
5
add1
square
double
;Also, sooner or later people will notice difficulties in communicating exceptional events up and down the chain and they would be greatly served by how Erlang/Elixir handles errors and process trees. Even if you want to stay in c# or f#, there's still wisdom to be gained by looking at how things work in functional languages and applying what you can in non functional languages.
It's not strange that he doesn't mention SML, Caml, OCaml, Miranda, Haskell etc given this context.
What would have been the way to make that more like a unix pipe? I didn't get to the bottom of it as time didn't permit.