Why you should learn functional programming
Jemima Abu introduces some of the key concepts of functional programing in prepation for her talk at Codemotion conference.
Table Of Contents
- What is functional programming?
- The attraction of functional programming
- How are you using functional programming today?
- Thoughts for developers interested in learning more
- Why should someone come along to your talk?
- Want to learn more about functional programming?
What is functional programming?
Jemima defines functional programming as “basically a way of programming using functions. It’s kind of like a mathematical approach to programming. So you expect answers based on the inputs that you gave — your input should always be equal to your output. So to do that, you want to make sure that there are no side effects anywhere, you’re not changing any values that you’re not supposed to be changing. This is very strict, clean programming.”
Functional programming is also about thinking about construction software differently by creating pure functions. It avoids concepts of shared state and mutable data which are typically observed in Object-Oriented Programming.
The attraction of functional programming
Jemima’s first interest in functional programming occurred when she started working with React. “We used to use class components. You have to define everything as a class, and it was a little binding. Then I got into React Hooks where you just define your components as functions. You don’t need to bind anything to anything because it’s just a function, and everything exists in that local scope of the function.”
Jemima learned that React Hooks operate using the functional programming method and class components operate using object-oriented programming methods. They let you use state and other React features without writing a class:
“Because I knew object-oriented programming from my days at school, where we had to learn about things like encapsulation, polymorphism, and inheritance, it was all very jumbled up when it came to the actual theory. But it was really the first time I saw the practical application and then I realised that Hooks are great.”
How are you using functional programming today?
Jemima is still working with react hooks and notes that Redux Reducers are also relevant when it comes to the principles of functional programming. She notes that a reducing redux has to be a pure function, meaning that it can only take in inputs, and then return on outputs based on the given input:
“So if you have a global state method, for example, in your Redux Reducer, your Redux reducer cannot modify that statement. It creates a new instance of the state method that is changed according to the act passed into it. You’re not trying to modify any global variables, you’re trying to always create new instances and then modify them, so you don’t have any side effects. That’s why we don’t do things like console logging, or handling synchronous calls because technically, those are side effects.”
Jemima notes that the practical applications of functional programming are particularly interesting relating to middleware when writing code: “You know you should not be doing this in reducers. But then sometimes you don’t really know why you’re not allowed to do that. And reducers are why you need middleware.”
Thoughts for developers interested in learning more
She suggests that you could use whatever programming language you like depending on what libraries you’re working with. It’s not like learning a new language as if you’re working with React, you’re using React Hooks, you use effects and Reducers and these concepts already exist. It’s more about understanding why they exist.”
Why should someone come along to your talk?
Jemima suggests that her presentation will be useful for people who are already working with React or are looking to get into React, especially anyone who is already working with class components. She suggests:
“If you make the switch to Hooks, or you work with state management libraries, and you want to understand the concepts behind how state management libraries work, or how you should rely on middleware as the manager applications. If you’re interested in learning the hows and whys of the concepts behind these languages, then you could show up to my talk.” It’s also a great talk for anyone looking to learn a new programming paradigm or understand the difference between object-oriented programming and functional programming.
Want to learn more about functional programming?
The Codemotion Virtual conference: The Italian Edition is held November 3–5, from 14:00 to 19:00 CET.
A single ticket grants you attendance to four conferences spread over the week, offering a deep dive into a plethora of topics relating to Backend, Frontend, Emerging Technologies, and AI / ML / DL. It’s a fantastic opportunity to learn first-hand about the best state-of-the-art technology, activities, good practices, and case studies for everyone working in tech regardless of your profile or your level of experience.
You can read the orginal version of this article at Codemotion.com, where you will find more related contents. https://www.codemotion.com/magazine/articles/events/learn-functional-programming/