---
title: "Short note: Functional programming"
subject: "Big Data Technologies"
chapter: 3
key: "semester_8/big_data_technologies:short-note-functional-programming"
source: https://www.bctengineer.com/q/semester_8/big_data_technologies/short-note-functional-programming
site: BCT Engineering
---

# Short note: Functional programming

Big Data Technologies · Chapter 3: Map-Reduce Framework

- Asked in: 2074 Bhadra, 5 marks
- Video: [What is functional programming?](https://www.youtube.com/watch?v=qOolkTDkE8E) — The Big Data Show
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_8/big_data_technologies/short-note-functional-programming
- Whole chapter: https://www.bctengineer.com/md/semester_8/big_data_technologies/chapter-3

## Question

Write a short note on Functional Programming.

## Short answer

Functional programming treats computation as evaluation of pure functions without side effects or mutable data. It uses higher-order functions like map and reduce, which inspired the MapReduce model, enabling automatic parallelization and fault tolerance through deterministic, side-effect-free operations.

## Answer

**Functional programming** is a programming paradigm in which computation is expressed as the evaluation of mathematical **functions**, avoiding changing state and mutable data. Languages: Lisp, Haskell, Scala, and functional features in Python, Java 8 and JavaScript.

#### Main characteristics

- **Pure functions:** the output depends only on the input, with no side effects. The same input always gives the same output.
- **Immutability:** data is not modified. Functions create new values instead.
- **First-class and higher-order functions:** functions can be passed as arguments, returned from other functions and stored in variables.
- **No shared state:** with no shared mutable variables, there are no locks or race conditions, so functions can safely run in parallel.
- **Recursion** is used instead of loops, and evaluation may be lazy.

#### Common higher-order functions

```python
nums = [1, 2, 3, 4]
squares = list(map(lambda x: x*x, nums))        # [1,4,9,16]
evens   = list(filter(lambda x: x % 2 == 0, nums))  # [2,4]
from functools import reduce
total   = reduce(lambda a, b: a + b, nums)      # 10
```

- **map** applies a function to each element.
- **filter** selects elements by a condition.
- **reduce (fold)** combines all elements into one value.

#### Relation to MapReduce

The MapReduce model is inspired by the `map` and `reduce` functions of functional languages like Lisp. Since map functions work on each record independently and do not change the input data, the framework can run thousands of them in parallel on different machines. Re-running a failed task gives the same result, because the functions are deterministic and side-effect free. This gives MapReduce its scalability and fault tolerance.

#### Advantages

- Easy parallelism and distribution
- Easy testing and debugging, because functions are independent
- Short, readable code

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What defines a pure function?
   A. It uses global variables
   B. Output depends only on input, with no side effects
   C. It always prints
   D. It uses loops only
   Answer: B. A pure function gives the same output for the same input and changes nothing outside. (Key point: Pure function)

2. Why does functional programming suit parallel execution?
   A. It uses locks heavily
   B. It requires one thread
   C. It uses mutable shared arrays
   D. No shared mutable state means no locks or race conditions
   Answer: D. Without shared mutable variables functions can safely run in parallel. (Key point: Parallelism)

3. How does functional programming help MapReduce fault tolerance?
   A. Deterministic, side-effect-free functions give the same result when a failed task is re-run
   B. It prevents machine failure
   C. It stores data twice
   D. It removes the master
   Answer: A. Re-running a task gives identical results because the functions are deterministic and side-effect free. (Key point: Relation to MapReduce)

4. What does reduce (fold) do in functional programming?
   A. Selects elements by condition
   B. Applies a function to each element
   C. Combines all elements into one value
   D. Sorts a list
   Answer: C. reduce combines elements, e.g. summing [1,2,3,4] to 10; filter selects and map applies. (Key point: reduce function)
