Functional Programming Part 1 - Concept

Learn how to use FP to refactor code.

September 3, 2025

These are my reading notes from the book Simplicity: Taming Complex Software with Functional programming.

Programming paradigms

There are two major programming paradigms:

Characteristics

"Classic" definition of FP

Now, let's talk about a bit of these two:

Side effects

Side effects refer to any behavior a function performs beyond simply returning a value.

Pure functions

A pure function always produces the same output when given the same input, and we called this "Mathematical functions".

In reality

In the real world, side effects are essential - they're the main reason we use software. After all, we want our programs to interact with the outside world, whether by displaying output, saving files, or sending network requests. Therefore, while functional programming emphasizes minimizing side effects, it doesn't eliminate them entirely - it just manages them more carefully.

Actions, Calculations and Data

When learning Functional Programming, we need to learn how to distinguish between three core concepts:

Let's have some examples:

Example 1:

{
  firstName: "Eric",
  age: 18,
};
 
sendEmailTo(to, from, subject, body);
sum(numbers);
saveUserDB(user);
string_length(str)
getCurrentTime()
[3, "hello", 5, 8]
// Actions
sendEmailTo(to, from, subject, body);
saveUserDB(user);
getCurrentTime();
 
// Calculations
sum(numbers);
string_length(str);
 
// Data
{
  firstName: "Eric",
  age: 18,
};
[3, "hello", 5, 8]

Example 2:

// Can you identify which one is action, calculation and data?
 
type WeatherStation = {
    id: string
    location: {
        latitude: number
        longitude: number
    }
    lastReading: number
    status: 'active' | 'offline'
}
 
calculateAverageTemperature(num);
saveUserProfile(id:string, name:string, email:string)
filterActiveStations(stations:WeatherStation[])
fetchLatestReadings()
convertToFahrenheit(celsiusTemp:number)
logUserActivity(id:string, action:string)
// Actions
saveUserProfile(id:string, name:string, email:string)
logUserActivity(id:string, action:string)
 
// Calculations
calculateAverageTemperature(num);
filterActiveStations(stations:WeatherStation[])
fetchLatestReadings()
convertToFahrenheit(celsiusTemp:number)
 
// Data
WeatherStation

Summary

Back to Blog 🏃🏽‍♀️