Forem

Cover image for Streams Oriented Programming
Dario Mannu
Dario Mannu

Posted on • Edited on

Streams Oriented Programming

If your app is all made of reactive streams plugged to the DOM by your framework, shall we give it a fancy name?

We could call it "Streams Oriented Programming", as it captures its essence very well.

What is this all about, exactly?

A programming paradigm, mostly derived from principles of Reactive Programming, in which you define everything as streams. Pretty much everything is (=can be, to be more precise) a stream that speaks the same language. If you use Observables, their "communication protocol" is subscribe/next/error/complete. You can use other patterns, different than just Observables, such as Callforwards, Callbags, Signals.

Image description

Why is this good for you?

Think of LEGO bricks: you can compose them so easily that every kid can do it.

If your apps all implement a unified compositional model, it becomes trivial to build large, complex applications that display higher quality and maintainability properties, in addition to a sharp reduction in the amount of code you'll write.

What are the top use cases?

Big Data ETL pipelines have done this since the age of scalability in a more or less informal way.

UI development in general is a great candidate because it hasn't broadly adopted this model and it's a great fit because everything can be represented as a stream: from clicks on a button which you turn into text to show on a page, to navigation, views, sequences of dialog boxes (wizards).

In JavaScript, most UI libraries or frameworks are conceived for the imperative programming paradigm, so this paradigm is novel.

Image description

LEGO bricks vs Jigsaw puzzles

Which comparison fits this paradign in a fair way?
Lego bricks you can be attached in a quite disorderly manner. On the other hand, jigsaw puzzles take a long time, especially at the beginning, to find two matching pieces.

Having worked with 100% streams-based simple and large enterprise applications I would say both can apply. When apps are small and simple, it's really like playing with LEGO bricks. When creating complex enterprise apps, the unique shape of each piece in the puzzle helps you only connect compatible pieces together...

Streams in action

If you'd like to see streams-based programming in action, you may want to check out rimmel.js, the only JavaScript UI library taking the "everything is a stream" approach. The results are remarkable.

Want to see concrete examples? Have a look at this Stackblitz collection

Learn More

Top comments (0)