The ongoing 4 month training course on the fundamentals of software development is soon coming to an end. The bunch of 15 students have been working 24/7 to learn the basics of modern web development. As the teacher of the course I have put quite an effort to emphasize the importance of functional programming. Learning the basics of fp even with a language like JavaScript pays off. React library has proven an invaluable tool to demonstrate the usefulness of the paradigm.
React is a well-known JavaScript library for implementing user interface components for single page Web applications. Current functional incarnation of React, which first appeared in 2019 leverages the idea of functions as a key building block to construct software. The appearance of any component is based on the parameters of a function instead of relying on the properties of an object. The library was functional from day one, but its latest versions are even more so.
The very idea of React is a sequence of function calls to manipulate a tree-like data structure called the DOM tree (i.e., a Web page). Functions are being called one after another and the result is a new representation of the DOM tree finally reflected in the user interface. The user interface is a pure function and therefore it is also called the ”referentially transparent UI” by the creators of React.
According to the creators of React ”React essentially manages to abstract away the DOM, thus simplifying the programming model while also in a somewhat surprising turn improving performance.” The resulting code has somewhat functional look and feel. Manipulating the DOM tree is hidden and classes are replaced by functions. The concepts introduced by the library not only highlight the power of pure functions but also guide the developer to keep one’s concerns separate and solutions composable.
Whereas React is a tool for managing the DOM tree without visible side-effects, Underscore.js, Ramda and lodash are well established JavaScript libraries for manipulating data in functional style. Rather than building software with the help of objects and methods, Underscore.js favors the ideas of pipelining and composing. Lodash follows the suite with similar concepts.
The utilities have become less useful over the last few years. The argument draws on the fact that the concepts introduced by the libraries have been adopted in ECMAScript version 6.
Ramda’s is a useful tool for dealing with data, but also for learning functional programming. A glimpse on Ramda documentation reveals a real world attempt to provide a generic functional programming library instead of a functional programming toolkit. The following citation from Ramda documentation reveals the goal of being positioned as a generic FP JS library – ”There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Ramda has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data”. Ramda’s functions are automatically curried, which is useful for learning to design partially applied and reusable functions.
Many software developers start their careers in Web development. The JavaScript code that runs in the context of a web browser with the help of a library such as React, provides a learning laboratory for students and prepares them for future multi-paradigm challenges. A functional programming library such as Ramda can add a great deal of functional look and feel to showcase algorithm design in a more declarative and functional way. Ramda is suitable for demonstrating side-effect free algorithm design with pure and curried functions.
JavaScript can be a good tool for learning and teaching the ideas of functional programming. Once the teaching of the language constructs is combined with teaching practices that are not only motivating, but also conceptually rewarding, we may be able to hit the sweet spot of designing learning solutions.
If JavaScript were taught along with libraries, such as React and Ramda, this might help the students to grasp the skills required by employers and make the learning curve for functional programming easier. The React library is moderately easy to learn and is suitable for teaching. Both libraries promote side-effect free style for writing software.
With this summary of how well React supports learning of functional programming our two men training team is gradually saying farewell to our students as they start their company internships in mid February 2021. We are grateful for all students for their hard work and persistent efforts during the theory period of the training course.
Also, we are happy to announce that some of the companies who have provided the internships for our students have shown interest in having their software development staff being introduced to functional programming.
Let’s spread the ”F” word and keep warm!
Selma the dog and the rest of the team
PS. It was fun to have a former student of the University of Nottingham on our training course. She recalled Graham Hutton’s interest in functional programming and was certainly delighted to see that our training course included fp topics, too.
Dogs need to keep war, too!