← Study Notes Programming Fundamentals


Programming Fundamentals

Functional Programming

Building programs from pure functions — same input, same output, no side effects — over immutable data. This makes code easier to test, reason about and parallelise, and it underlies React, Redux and stream pipelines. The cost is more allocation and a mental shift from mutating state to transforming it with map, filter and reduce.


Purpose

Functional programming builds logic from pure functions — same input, same output, no side effects — operating on immutable data. It exists because shared mutable state is the root of a huge class of bugs; removing it makes code dramatically easier to test, reason about and parallelise.

When to Use It

Its ideas power much of the modern stack: React's render-as-a-function-of-state, Redux reducers, stream and data pipelines, and map/filter/reduce transformations everywhere. Even in imperative codebases, keeping the core logic pure and pushing side effects (I/O, mutation) to the edges pays off immediately.

Trade-offs

Immutability allocates new values instead of mutating old ones, which costs memory and sometimes speed; deeply functional idioms can also read as alien to teams trained imperatively. Most codebases land on a pragmatic blend — pure logic, controlled effects — rather than full purity.

Implementation

Write functions that take inputs and return outputs without touching outside state; treat data as values to transform, not places to update. Use map/filter/reduce over hand-rolled loops where clearer, and isolate side effects behind a thin boundary so the rest of the code stays referentially transparent.