Skip to main content

Short note: 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.

Write a short note on Functional Programming.

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

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

✓ Answer checked by Claude Opus 5.5 (high effort)

All Big Data Technologies chapter 3 questions →