Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Reactive Programming for .NET Developers

You're reading from  Reactive Programming for .NET Developers

Product type Book
Published in Jul 2016
Publisher Packt
ISBN-13 9781785882883
Pages 276 pages
Edition 1st Edition
Languages

Table of Contents (15) Chapters

Reactive Programming for .NET Developers
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
First Steps Toward Reactive Programming Reactive Programming with C# Reactive Extension Programming Observable Sequence Programming Debugging Reactive Extensions CLR Integration and Scheduling Advanced Techniques F# and Functional Reactive Programming Advanced FRP and Best Practices

Chapter 9. Advanced FRP and Best Practices

In the previous chapter, we introduced a 360-degree description of FRP. We discussed the main features related to this type of programming, passing from a theoretical introduction to the concrete examples of the scenarios. We also described how the Event module of the F# language exposes functionalities to manage the Event type delegate in the .NET Framework and how this module amplifies its capabilities, adding also a set of functionalities to manage events, such as collection (the IObservable interface). Finally, we conclude the chapter showing the main differences between push-based and pull-based scenarios.

FRP is not a simple subject to understand; in fact, it is frequently considered very difficult to assimilate. This problem depends on the complexity of the concepts; anyway, once you understand their meaning, it is not so straightforward to put them into practice. In other words, the only relatively simple aspect is the presence of objects...

Discrete and continuous components


Discrete and continuous components are fundamental to better understand FRP. From the first introduction, one of the main axes is exactly the distinction between discrete and continuous. In the previous chapter, we analyzed many aspects related to these two components, but we never mentioned them. If we had so, then the argument could have been too complicated and theoretical.

By definition, discrete and continuous components can be described as the two main characteristics which FRP provides. In other words, they are the basics to apply time flow in our application or to improve our scenario of use.

We previously discussed the execution of the following function:

List.map (fun x -> x ** x) 

While doing so, we introduced the concept of time flow to underline that every execution of the mathematical function power occurs step by step.

In the example, it seems that this scenario is continuous, because for every input value of the list, a new output value...

Time flow and dynamic change


Time flow and dynamic change are now clear concepts of FRP. In the previous chapter, we discussed over and over again what they are. They represent one of the main axes of FRP together with discrete and continuous semantics.

Concerning reactive systems (hybrid systems), we immediately understood how much important the concepts of execution time and used memory are. These two features may have some problems that could make the system nonreactive. The title of this section suggests a solution for them both. The following are the methods which can be used:

  • A good approach to avoid prolonged execution time or, even worse, the inability to manage the time flow; this results in having control on information flow (data or events)

  • Instead, if we want to control used memory, for example, useless information or instances, it would be interesting to use a dynamically changing system according to the information obtained and architecture that already support these two features...

Even more on FRP and F#


The second half of the chapter shows how we can make the best use of F# and what the Microsoft .NET Framework makes available to enjoy and adopt FRP.

In the last few years, technology has evolved at an increasing rate. Nowadays, everything is connected and, in the future, each and every device will be able to receive and send data to and from each other. This will certainly lead to a technical evolution about the way we write the code. Let's think, only for a minute, about the notification messages that appear in our smartphone, our personal computer, and even in our smartwatch. All these need is a reactive system that is able to send millions if not billions of these messages simultaneously on multiple devices.

This is why functional programming and (Functional) Reactive Programming in particular play a key role in this evolution.

Social networks, e-commerce servers dedicated in sending information from and to IoT devices, are already using hybrid systems that complement...

Summary


In this chapter, we further deepened the main concepts of FRP.

In the first part, we presented the main differences between the discrete and continuous components, showing both theoretical analysis and examples of code. Afterward, we discussed the time flow and the asynchronous data flow. Then, we introduced Computation Expressions and also the concept of Monad.

In the second and last half of the chapter, we discussed the flow of choices, Railway-oriented Programming, and finally, the module Observable.

On reaching this point, we acquired all theoretical basic information to apply Reactive Programming and Functional Reactive Programming.

It is fundamental to understand how much these two paradigms are continuously intertwined. In fact, talking about Linq and Rx is almost the same as FRP and vice versa.

On the Web, there are not many concrete examples about using FRP through F# language. However, with little practice and knowledge of functional language Haskell, on the site Microsoft Academic...

lock icon The rest of the chapter is locked
arrow left Previous Chapter
You have been reading a chapter from
Reactive Programming for .NET Developers
Published in: Jul 2016 Publisher: Packt ISBN-13: 9781785882883
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}