
Pipelines – a guided tour of the new IO API in .NET - benaadams
https://blog.marcgravell.com/2018/07/pipe-dreams-part-1.html
======
nathanaldensr
As Tychus Findlay might say, "It's about damned time."

The Stream API has to be one of the ugliest warts in .NET, _and it 's been
around since the beginning._ I am _so glad_ Microsoft finally addressed it.
Every time I use Stream, I am reminded of how badly the Stream API violates
SOLID principles.

I like how Microsoft approached the problem from below by introducing new
types like Span<T> and Memory<T>, _then_ the Pipes API. It shows that the
future of the platform is in good hands.

~~~
quiq
First job out of school my coworker was talking about how nice dotnet Stream
API was. I had a Stream. Streams have Position. A GZipStream is a Stream. A
GZipStream does not have position. Countless hours of Java style "OOP"
indoctrination flashed before my eyes and I realized that even something as
big as Dotnet could do such a thing. It made me feel like a kid that just
realized their parents aren't infallible.

~~~
sk5t
I dunno, I'd prefer a consistent Stream interface that just sometimes doesn't
have a position, and wraps other Streams with little fuss, rather than have to
change gears into Source/Sink lexicon.

~~~
quiq
I see where you're coming from, and hey, the thing works. Not everything is
perfect, but the Stream API could _definitely_ be better.

I agree it would be nice to have a consistent interface. The problem is it's
neither consistent nor an interface, it's an inconsistent hierarchy of
subclasses. There's always fuss because everyone is going to get bitten by it
at some point. It's just a poor abstraction, and it leaves a bad taste in your
mouth as a library (well, framework) consumer.

Microsoft promised me that they gave me a thing that had certain features and
capabilities using industry standard terminology and knowledge. There's a
contract. If you go out for a car loan that says "0% APR for 12 months!" You
expect that to be the first 12 months, not "0% APR only on days divisible by 7
during leap years, up to a total of 12 * 30 days over the course of the next
millennium, otherwise 7.5%"

~~~
nathanaldensr
Thank you for eloquently summarizing my "violates SOLID principles" comment.
Rigid OOP class hierarchies suck, in general.

------
steveadoo
I had some trouble using ReadOnlySequence in a library I am writing (mostly
because of no documentation). After looking through how Kestrel uses it(they
started using Pipelines in ASP.NET Core 2.1) I found their BufferReader[1]
class. It made using ReadOnlySequence much easier.

Overall, pipelines have been really solid for me so far. Working out how to
use it without documentation was a total pain though, hopefully they get that
out soon. If anyone is interested I can throw the library up on GitHub if
anyone wants some real world examples of using pipelines.

[1]
[https://github.com/aspnet/Common/blob/master/shared/Microsof...](https://github.com/aspnet/Common/blob/master/shared/Microsoft.Extensions.Buffers.Sources/BufferReader.cs)

~~~
Haldir
[https://www.codemag.com/Article/1807051/Introducing-.NET-
Cor...](https://www.codemag.com/Article/1807051/Introducing-.NET-
Core-2.1-Flagship-Types-Span-T-and-Memory-T) might help with Readonlysequence
too

------
algorithmsRcool
David Fowler (The architect of this API) is brilliant! The Pipelines API
turned out better than I ever expected.

~~~
skc
His work rate is pretty impressive.

------
moomin
This is literally the most documentation on the internet for this API. AFAICT,
though, it doesn't have compression or encryption stages, yet?

~~~
algorithmsRcool
Since the entire design of Pipelines is 0-copy, I figure you would have to
manually pull from one pipe, operate on it and push the resulting data into
another pipe.

Im sure there is an example of connecting pipes together like this somewhere.
Maybe in Kestrel or SignalR (Core)?

~~~
josteink
> Im sure there is an example of connection pipes together like this
> somewhere. Maybe in Kestrel or SignalR?

Last I checked, SignalR haven’t had a release in years, so I wouldn’t go there
looking for news.

~~~
algorithmsRcool
SignalR Core is what i meant.

It is alive an under active development on .NET Core

[https://github.com/aspnet/SignalR](https://github.com/aspnet/SignalR)

~~~
josteink
That’s definitely something different and you appear to be correct:

[https://github.com/aspnet/SignalR/search?q=pipelines&unscope...](https://github.com/aspnet/SignalR/search?q=pipelines&unscoped_q=pipelines)

------
manigandham
Part 2 here: [https://blog.marcgravell.com/2018/07/pipe-dreams-
part-2.html](https://blog.marcgravell.com/2018/07/pipe-dreams-part-2.html)

------
tigershark
Very nice post, I’m eagerly waiting for the next parts.

