Live data from Hacker News

An introduction to Reactive Programming

gist.github.com

21–30 of 78 posts

Re: An introduction to Reactive Programming

#21

Pardon my blunt question, but who is the heck is this for? Is this a sideways method of pushing React.js? Or is this for assembly programmers as well, and I just don't get it?

It has nothing to do with React (in fact, React, despite its name, does not represent the paradigm of reactive programming).

This is for javascript programmers who enjoy functional programming and want an introduction into Rx.js library. It may also be of interest for programmers in other languages (because rx has been implemented in many of them).

Re: An introduction to Reactive Programming

#22

While this may be technically sound, I think this is not the most fundamental way of explaining FRP. FRP is just a toy really. It's a useful toy that help to grasp and use an advanced programming concept. Let me explain. That concept originates from a common programming mistake. A common mistake is to use compulsive caching . It's the tendency to store function results in a variable just because this result is gonna…

This "assignment is caching is bad" analogy does not hold any water.

You get a result from a call to `foo(bar)`. You have to _do something_ with that result. One common thing you'd need to do is to call another function: _baz(foo(bar))_. But then you're just hiding the assignment inside a baz function call (the result of _foo(bar)_ will be available as a variable/constant inside of _baz_).

That doesn't so bad if you only need to do one thing with with the result of `foo(bar)`. Now what if you have to do something with that result twice. In this case all you've done is reduce the scope of a constant to be smaller than it needs to be, requiring you to make a duplicate `foo(bar)` call.

Now you're repeating yourself and you don't know anymore if you're conceptually dealing with the same result or if foo(bar) might produce a different result on second call. You removed philosophical/semantic meaning from your code and did not gain anything from it.

If you find yourself wanting/needing to "expire" variables that you define before you run out of scope, then the answer is a combination of:

1) use constants of immutable data structures, not variables or mutable structures 2) better name such constants so that you know what they represent 3) better manage scope and function size

In practice, the above is much easier to achieve than what you're proposing, and makes the code easier to read and maintain.

> The right way instead is to evaluate (or "re-evaluate") the function every time you need it unless you have a good reason not to (the only good reason is that the function is a bottleneck that affects the experience of the user)

That does not scale to using the coding paradigm that you're proposing application-wide. Your whole app will be one big bottleneck because it's doing a multiple of the computations that it needs to be doing, with no easy way out. I guess you can get away with that by throwing more money at your backend infra, but you can't do that on mobile or for web frontends or desktop apps.

Re: An introduction to Reactive Programming

#23
post #17
post #6

My shop specializes in multiplatform FRP applications via the reflex haskell library [0]. After many years of wrangling FRP my biggest learned lesson is certainly this: not everything is a stream! You need to be able to mix streams (also called events), which embody push semantics and behaviors (things you can sample), which embody pull semantics. This is important for performance and for the structure of large appli…

One of the teams I was on solved the pull behavior by having an "immediately publish last known value on subscription" parameter we could pass in when subscribing. This solved most of our needs around pulling data. We weren't doing a full FRP system, no composable streams, just building a system in which the only way to communicate was through subscriptions between components. This worked really well in practice, for…

So its like an rxjs BehaviorSubject?

Re: An introduction to Reactive Programming

#24
post #17

Earlier quoted context omitted.

One of the teams I was on solved the pull behavior by having an "immediately publish last known value on subscription" parameter we could pass in when subscribing. This solved most of our needs around pulling data. We weren't doing a full FRP system, no composable streams, just building a system in which the only way to communicate was through subscriptions between components. This worked really well in practice, for…

So its like an rxjs BehaviorSubject?

Not quite sure, haven't looked into rxjs much.

We were running on an embedded micro with 256KB of RAM, so just making everything async and callback based was already pushing the boundaries of the industry. Vendors we worked with got extremely confused when we said they needed to hand us async code, that they had a few milliseconds to run in before they relinquished control, and that busy loops were verboten.

I really miss working in a code base where every component can be trivially subscribed to.

On the flip side, I've seen subscriptions taken too far, as people make every single value on a form a separate subscription. Seriously, it is A-OK to give the First and Last names together when the user hits submit.

Re: An introduction to Reactive Programming

#26
This is great, and if anyone is looking for additional examples in a library that is a bit different from the others check out Racket’s reactive programming library.

docs.racket-lang.org/frtime

This was how I was introduced to reactive programming 5 or so years ago.

Re: An introduction to Reactive Programming

#28

Pardon my blunt question, but who is the heck is this for? Is this a sideways method of pushing React.js? Or is this for assembly programmers as well, and I just don't get it?

I've thought this would be a good way to write video games, but most engines don't support the sort of functional programming that would make this pleasant to use, so I wind up creating events which solve similar kinds of problems. For games, the primary benefit would be to decouple various game components so you can create and remove them without having to worry about a complex web of dependencies and state. It keeps things declarative, which also helps the web of interdependedness problem of many, overlapping systems.

Re: An introduction to Reactive Programming

#29
post #7

> "this new thing called Reactive Programming" Let's take an age-old paradigm and present it as something new... why, I don't know, maybe so we can come across as an expert on something "new" and high-tech for fame and fortune... ...at least until someone who has been around the block comes along and figures out you're at best a bullshit artist and at worst completely ignorant and unqualified to be presenting...

Oh, stop.

Re: An introduction to Reactive Programming

#30
post #6

My shop specializes in multiplatform FRP applications via the reflex haskell library [0]. After many years of wrangling FRP my biggest learned lesson is certainly this: not everything is a stream! You need to be able to mix streams (also called events), which embody push semantics and behaviors (things you can sample), which embody pull semantics. This is important for performance and for the structure of large appli…

Flapjax had behaviors, as you describe, as a key facility in a JavaScript FRP implementation, dating back to 2008:

https://github.com/brownplt/flapjax/blob/f92e99ea25a4533c4ab...

I "discovered" FRP in 2011, when I stumbled upon Flapjax — spent a month pouring over the source code, learned a lot, my brain has never been the same since!

Post reply on HN