Skip to content

Functional Programming

Let's first look at what a function is. A function is one of the most basic tasks; a large program can be viewed as a top-level function calling several lower-level functions, which can, in turn, call other functions. Thus, a large task is decomposed and executed in layers. Therefore, a function is the fundamental unit of procedural programming.

Java does not support the standalone definition of functions, but we can treat static methods as independent functions and instance methods as functions that carry the this parameter.

Functional Programming (note the addition of "式" in the term) is a programming paradigm that, while it can also be classified as procedural programming, aligns more closely with mathematical computation.

Concepts of Computer and Compute

We must first understand the concepts of Computer and Compute.

At the computer level, the CPU executes instructions for addition, subtraction, multiplication, division, as well as various conditional checks and jump instructions. Thus, assembly language is the language closest to the computer.

On the other hand, "compute" refers to mathematical computation; the more abstract the computation, the further it is from the hardware of the computer.

In programming languages, lower-level languages are closer to the computer, have low abstraction, and high execution efficiency, such as C language. Conversely, higher-level languages are closer to computation, have high abstraction, and lower execution efficiency, such as Lisp.

Characteristics of Functional Programming

Functional programming is a highly abstract programming paradigm. Functions written in pure functional programming languages do not have variables. Therefore, for any given function, if the input is determined, the output is also determined. Such pure functions are said to have no side effects. In contrast, programming languages that allow variable usage have uncertain variable states within functions, which can yield different outputs for the same input. Thus, these functions are said to have side effects.

One characteristic of functional programming is that it allows functions to be passed as parameters to other functions and also permits functions to be returned!

Functional programming originated from a set of function transformation logic studied by mathematician Alonzo Church, also known as Lambda Calculus (λ-Calculus). As a result, functional programming is often referred to as Lambda Calculus.

The Java platform has supported functional programming since Java 8.

Functional Programming has loaded