Many people wonder, "What is functional programming?" To answer that, let's first consider why we'd want to use it. Imagine you're using a computer language like Java or C++, or even the simpler C language. You've probably encountered a frustrating problem: some bugs are hard to find and fix.
One reason is that they're tricky to recreate, and when you do, it's tough to keep track of all the changes happening in a big program. In large programs, thousands of things are happening at once, and this can lead to difficult-to-recreate bugs.
Functional programming aims to solve this problem. When you learn to use it, you'll discover techniques to create large, powerful, and mostly bug-free programs made up of smaller, easy-to-test pieces.
At its core, functional programming is about organizing complex ideas in programs while keeping the code easy to test and change. Object-oriented programming, which you might be familiar with, also aims for this, but it doesn't always succeed.
The key difference is how they organize code. Object-oriented programming thinks in terms of objects and their relationships, while functional programming brings in mathematical precision.
Functional programming reduces the chance of bugs by using math-like functions. Even though there will always be some room for human error, adding mathematical certainty makes it easier to avoid bugs.
Imagine if everything in a program could be represented as a simple math equation – bugs would be hard to hide!
We'll explore functional programming and its differences from object-oriented programming in more detail later.
Since many of you are likely more familiar with object-oriented programming, I'll use it as a reference point to help you understand functional programming concepts better.