I would like to understand if the principles behind the Reactive Application manifesto can be achieved using a non-functional language.
Some people say that since FP use immutable states and free side-effects functions, they are easier to implement concurrent, distributed and resilient systems.
But how can we achieve that using Java for example?
There are some frameworks like Apache Camel, that have some components to work with, like Camel RX, and Camel SEDA.
Are these frameworks enough?
I will try to clarify my question:
I think of reactive programming as new programming paradigm, and a new programming paradigm requires new tools and frameworks.
Functional languages deals with objects differently, that's why there's a lot of articles about FRP working with things event-based and asynchronously.
But now, backing to Java, or other Object Oriented language, let's think in a Web Application:
- How can we create a java web application that makes use of good event-based frontend.
- These events then pass information asynchronously in a smooth way to the backend.
- The backend can scale easily and be resilient as well.
I know that is possible to create an application that accomplish these requirements using java, and servlets, and EJBs, but my question is, can we do it differently? More close to a reactive approach?
I thought something like this:
- A nice ajax framework in the frontend, that makes the "passing information" with the backend smoothly.
- In the backend a way to use a framework or library (Camel SEDA ou Camel RX) to execute things in parallel.
Do you think this is a good approach?
Well, if you take a look at the Reactive manifesto you reference, you'll see that the word "functional" does not appear there at all. Instead, there are 4 specific criteria that are used to define what a "reactive" application is:
Nothing in Java prohibits you from implementing any of those traits (barring the "responsive" for the very rare, extremely high-performance scenarios). And nothing in Java prohibits you from writing code constrained to immutable objects and side-effect-free functions (in fact, some libraries, like Guava, encourage you to use immutable objects as well as reify functions).
Frameworks like RxJava can further help you write application that fulfill the criteria defined in the manifesto, by providing an event-driven system oriented around data flows, which is basically the core tenet of reactive programming.
Reactive Programming is not new, but it is new to most people. It is simply another name for dataflow that has been around since the 1960's. The Reactive Manifesto is just way to describe the best qualities of Dataflow and Reactive Programming.
A functional language is certainly not needed nor is a huge library. I've implemented many dataflow systems. Most of them are more of a collection of helper functions than what most would call a "library." It really depends what type of features you want in the system.
Dataflow is a very "wide" topic. The system could include many nice-to-have features or it could just have the basics. The core of dataflow is that the data controls execution. This is in contrast to "contol-flow" (used in all mainstream languages like C# and Java) where you tell the computer when, where and how to process the data. The most common form of dataflow is the Pipeline model... a series of boxes (or nodes) connected sequentially to one another with links (aka pipes, wires or arcs).
I have just started to examine the libraries available for Java dataflow programming so I can't give you a specific answer right now. It seems that RxJava is current "name-brand" for dataflow in Java so I would start there. In my upcoming book (http://DataflowBook.com) I will devote a whole section to the available dataflow libraries in common languages, including Java.
Defining reactive is the first step. For example:
In terms of existing APIs, a few which fit the bill (event-driven, scalable, resilient, responsive) would be:
Another RDF Parser (ARP)
Event Delivery Network (EDN)
Jini
References