Why you should learn functional programming

Table Of Contents

Looking for something new without the need for frameworks and libraries? Do you like maths? You might want to take a look at how you can functionally program with JavaScript and apply functional programming to your application to optimize your code. Jemima Abu is a self-taught Front End Developer and school-taught Systems Engineer from Lagos, Nigeria who currently works at Lithuanian software company Telesoftas. I connected with her before her presentation at Codemotion’s online conference: The Italian edition to find out more about functional programming with JavaScript.

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

According to Jemima, a developer may be working with functional programming more than they realise: “Some people think of paradigms as very strict. You have languages where you have to follow specific principles like Haskell or Scala. But JavaScript is like this big bowl of wibbly, wobbly programming, where nothing is fixed. So you can use whatever power that works for you. it’s just up to you to decide okay, so I know how to write these components in a functional way. But now I want to understand why I need to write them out.”

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?

Join Jemima to learn more at our upcoming digital conference where she’ll properly delve into the concept of functional programming in JavaScript and explore some real life applications of the benefits of writing functional code.

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/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Codemotion

Codemotion

63 Followers

We help tech communities to grow worldwide, providing top-notch tools and unparalleled networking opportunities.