{"id":1729,"date":"2022-12-13T09:39:11","date_gmt":"2022-12-13T09:39:11","guid":{"rendered":"https:\/\/blog.amt.in\/?p=1729"},"modified":"2022-12-13T10:09:56","modified_gmt":"2022-12-13T10:09:56","slug":"insights-on-reactive-programming","status":"publish","type":"post","link":"https:\/\/blog.amt.in\/index.php\/2022\/12\/13\/insights-on-reactive-programming\/","title":{"rendered":"Insights on Reactive Programming"},"content":{"rendered":"<p>In\u00c2\u00a0computing,\u00c2\u00a0reactive programming\u00c2\u00a0is a\u00c2\u00a0declarative\u00c2\u00a0programming paradigm\u00c2\u00a0concerned with\u00c2\u00a0data streams\u00c2\u00a0and the propagation of change. With this paradigm it is possible to express static (e.g., arrays) or dynamic (e.g., event emitters)\u00c2\u00a0data streams\u00c2\u00a0with ease, and also communicate that an inferred dependency within the associated\u00c2\u00a0execution model\u00c2\u00a0exists, which facilitates the automatic propagation of the changed data flow.<\/p>\n<p>For example, in an\u00c2\u00a0<i>imperative<\/i>\u00c2\u00a0programming setting,\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a:=b+c}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/bc149fd407b1251ef20a491213bbf4e600a4e982\" alt=\"a:=b+c\" \/><\/span>\u00c2\u00a0would mean that\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/ffd2487510aa438433a2579450ab2b3d557e5edc\" alt=\"a\" \/><\/span>\u00c2\u00a0is being assigned the result of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle b+c}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/d7db36971debb247704a03ec6c3832d8fecdb05b\" alt=\"b+c\" \/><\/span>\u00c2\u00a0in the instant the expression is evaluated, and later, the values of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle b}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/f11423fbb2e967f986e36804a8ae4271734917c3\" alt=\"b\" \/><\/span>\u00c2\u00a0and\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle c}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/86a67b81c2de995bd608d5b2df50cd8cd7d92455\" alt=\"c\" \/><\/span>\u00c2\u00a0can be changed with no effect on the value of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/ffd2487510aa438433a2579450ab2b3d557e5edc\" alt=\"a\" \/><\/span>. On the other hand, in\u00c2\u00a0<i>reactive<\/i>\u00c2\u00a0programming, the value of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/ffd2487510aa438433a2579450ab2b3d557e5edc\" alt=\"a\" \/><\/span>\u00c2\u00a0is automatically updated whenever the values of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle b}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/f11423fbb2e967f986e36804a8ae4271734917c3\" alt=\"b\" \/><\/span>\u00c2\u00a0or\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle c}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/86a67b81c2de995bd608d5b2df50cd8cd7d92455\" alt=\"c\" \/><\/span>\u00c2\u00a0change, without the program having to re-execute the statement\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a:=b+c}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/bc149fd407b1251ef20a491213bbf4e600a4e982\" alt=\"a:=b+c\" \/><\/span>\u00c2\u00a0to determine the presently assigned value of\u00c2\u00a0<span class=\"mwe-math-element\"><span class=\"mwe-math-mathml-inline mwe-math-mathml-a11y\">{\\displaystyle a.}<\/span><img decoding=\"async\" class=\"mwe-math-fallback-image-inline\" src=\"https:\/\/wikimedia.org\/api\/rest_v1\/media\/math\/render\/svg\/6b803da9c45c1186883bde55107e9ccb102c92c6\" alt=\"a.\" \/><\/span><\/p>\n<p>Another example is a\u00c2\u00a0hardware description language\u00c2\u00a0such as\u00c2\u00a0Verilog, where reactive programming enables changes to be modeled as they propagate through circuits.<\/p>\n<p>Reactive programming has been proposed as a way to simplify the creation of interactive user interfaces and near-real-time system animation.<\/p>\n<p>For example, in a\u00c2\u00a0model\u00e2\u20ac\u201cview\u00e2\u20ac\u201ccontroller\u00c2\u00a0(MVC) architecture, reactive programming can facilitate changes in an underlying\u00c2\u00a0<i>model<\/i>\u00c2\u00a0that are reflected automatically in an associated\u00c2\u00a0<i>view<\/i>.<\/p>\n<p>Several popular approaches are employed in the creation of reactive programming languages. Specification of\u00c2\u00a0dedicated\u00c2\u00a0languages that are specific to various\u00c2\u00a0domain constraints. Such constraints usually are characterized by real-time, embedded computing or hardware description. Another approach involves the specification of\u00c2\u00a0general-purpose\u00c2\u00a0languages that include support for reactivity. Other approaches are articulated in the definition, and use of programming\u00c2\u00a0libraries, or\u00c2\u00a0embedded\u00c2\u00a0domain-specific languages, that enable reactivity alongside or on top of the programming language. Specification and use of these different approaches results in language\u00c2\u00a0capability trade-offs. In general, the more restricted a language is, the more its associated compilers and analysis tools are able to inform developers (e.g., in performing analysis for whether programs are able to execute in actual real time). Functional trade-offs in specificity may result in deterioration of the general applicability of a language.<\/p>\n<p>A variety of models and semantics govern the family of reactive programming. We can loosely split them along the following dimensions:<\/p>\n<ul>\n<li>Synchrony: is the underlying model of time synchronous versus asynchronous?<\/li>\n<li>Determinism: Deterministic versus non-deterministic in both evaluation process and results<\/li>\n<li>Update process: callbacks versus dataflow versus actor<\/li>\n<\/ul>\n<h4><span id=\"Essence_of_implementations\" class=\"mw-headline\">Essence of implementations:<\/span><\/h4>\n<p>Reactive programming language runtimes are represented by a graph that identifies the dependencies among the involved reactive values. In such a graph,\u00c2\u00a0<i>nodes<\/i>\u00c2\u00a0represent the act of computing and\u00c2\u00a0<i>edges<\/i>\u00c2\u00a0model dependency relationships. Such a runtime employs said graph, to help it keep track of the various computations, which must be executed anew, once an involved input changes value.<\/p>\n<h4><span id=\"Change_propagation_algorithms\" class=\"mw-headline\">Change propagation algorithms:<\/span><\/h4>\n<p>Various abstract implementation approaches enable the specification of reactive programming. The flow of data is explicitly described with employment of such a graph. The most common algorithms are:<\/p>\n<ul>\n<li>pull<\/li>\n<li>push<\/li>\n<li>hybrid push-pull<\/li>\n<\/ul>\n<h4><span id=\"Degrees_of_explicitness\" class=\"mw-headline\">Degrees of explicitness:<\/span><\/h4>\n<p>Reactive programming languages can range from very explicit ones where data flows are set up by using arrows, to implicit where the data flows are derived from language constructs that look similar to those of imperative or functional programming. For example, in implicitly lifted\u00c2\u00a0functional reactive programming\u00c2\u00a0(FRP) a function call might implicitly cause a node in a data flow graph to be constructed. Reactive programming libraries for dynamic languages (such as the Lisp &#8220;Cells&#8221; and Python &#8220;Trellis&#8221; libraries) can construct a dependency graph from runtime analysis of the values read during a function&#8217;s execution, allowing data flow specifications to be both implicit and dynamic.<\/p>\n<p>Sometimes the term\u00c2\u00a0<i>reactive programming<\/i>\u00c2\u00a0refers to the architectural level of software engineering, where individual nodes in the data flow graph are ordinary programs that communicate with each other.<\/p>\n<h4><span id=\"Static_or_dynamic\" class=\"mw-headline\">Static or dynamic:<\/span><\/h4>\n<p>Reactive programming can be purely static where the data flows are set up statically, or be dynamic where the data flows can change during the execution of a program.<\/p>\n<p>The use of data switches in the data flow graph could to some extent make a static data flow graph appear as dynamic, and blur the distinction slightly. True dynamic reactive programming however could use imperative programming to reconstruct the data flow graph.<\/p>\n<h4><span id=\"Higher-order_reactive_programming\" class=\"mw-headline\">Higher-order reactive programming:<\/span><\/h4>\n<p>Reactive programming could be said to be of\u00c2\u00a0higher order\u00c2\u00a0if it supports the idea that data flows could be used to construct other data flows. That is, the resulting value out of a data flow is another data flow graph that is executed using the same evaluation model as the first.<\/p>\n<h4><span id=\"Similarities_with_observer_pattern\" class=\"mw-headline\">Similarities with observer pattern:<\/span><\/h4>\n<p>Reactive programming has principal similarities with the\u00c2\u00a0observer pattern\u00c2\u00a0commonly used in\u00c2\u00a0object-oriented programming. However, integrating the data flow concepts into the programming language would make it easier to express them and could therefore increase the granularity of the data flow graph. For example, the observer pattern commonly describes data-flows between whole objects\/classes, whereas object-oriented reactive programming could target the members of objects\/classes.<\/p>\n<p>The above is a brief about Reactive Programming. Watch this space for more updates on the latest trends in Technology.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In\u00c2\u00a0computing,\u00c2\u00a0reactive programming\u00c2\u00a0is a\u00c2\u00a0declarative\u00c2\u00a0programming paradigm\u00c2\u00a0concerned with\u00c2\u00a0data<\/p>\n","protected":false},"author":1,"featured_media":1731,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[925,618,7],"tags":[926,619,18],"class_list":["post-1729","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-paradigm","category-reactive-programming","category-techtrends","tag-programming-paradigm","tag-reactive-programming","tag-technology"],"_links":{"self":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1729","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/comments?post=1729"}],"version-history":[{"count":1,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1729\/revisions"}],"predecessor-version":[{"id":1730,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/posts\/1729\/revisions\/1730"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media\/1731"}],"wp:attachment":[{"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/media?parent=1729"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/categories?post=1729"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.amt.in\/index.php\/wp-json\/wp\/v2\/tags?post=1729"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}