⬆️ ⬇️

JavaScript in 2016: functional programming has come seriously and for a long time

In 2015, you may have noticed a change in how JavaScript is developed. Developers are moving away from an unpredictable architecture with a mutable state in the direction of a more predictable, immutable application architecture .



With such frameworks as Backbone, it was customary to synchronize the data itself and the presentation of the data - for this, you had to manually subscribe to the necessary dom events. This method was error prone and forced to use too much generic code. Angular came and corrected it with the help of automated bilateral binding.



But now everything is moving in a different direction.



Together with React and its tools, for example, Redux, the immutable approach makes it easier to write code than using the traditional, mutable state. When using the mutable state, the application cannot take advantage of modern tools, for example, live reloading. Therefore, I really want to leave everything to be immune.

')

Libraries based on the functional programming paradigm (the same Redux) are easier to expand - because pure functions fit better. Such libraries usually have fewer lines of code, which means fewer bugs and less complexity. For fun, take a look at the Redux source code . To view it, it takes less than 15 minutes - in fact, a bit.



Compatibility and reduced complexity means that the toolkit can achieve the highest quality. Such things as live reloading and time-travel-debugging cannot be quickly and easily implemented for applications made in an imperative style. Although technically possible, the side effects of the functions will interfere.



Let's not forget that frameworks and libraries come and go. It is likely that React will not be the most popular technology in a year or two. But the whole point is that the functional paradigm, which became widespread thanks to React and other functional libraries, will remain. The toolkit is so good that there is no going back. After you have started using live reloading and time-travel-debugging, you definitely won't want to go back. These things really increase productivity .



The future lies in interactive program development. If you want to get acquainted with the examples made in the framework of interactive programming, look at the Bret Victors homepage . Pay attention to his report “Inventing on Principle” .



The function code is usually less prone to bugs. True, the frontend developers are moving in this direction for another reason. Functional programming does not offer anything fundamentally new. The reason is in the tools, and in that you can reduce the number of bugs. A simpler code is a side (and nice) effect.



findings



Even if React is not a super-popular technology in the future, the philosophy of functional programming will remain.



If you are new to functional programming, I recommend looking at Haskell. The book “Learn You a Haskell for a Great Good” is in the public domain . It is worth exploring Haskell to gain in-depth knowledge of programming, even if you are not going to use this language for any serious project. I also recommend to look at this article , which shows with examples where functional programming is used.



Thanks for attention. Follow the author’s Twitter account if you are interested in such stories.



about the author



Hello! My name is Mark, I am a software developer. I live in Germany. I love to play with new technologies. You can view my Android app and find out more facts about me .



If you like the post, subscribe to my email newsletter.

Source: https://habr.com/ru/post/306550/



All Articles