A Crash Course In Functional Programming (Part I)

Tech At Tommy
techattommy
Published in
4 min readJun 26, 2019

--

Written by Jayd Pather

The Development Teams at Tommy Hilfiger are dedicated to knowledge sharing, and this article provides an overview of functional programming. Part I intended for all audiences, including those without an IT background. In the second half of this series, we’ll dive into content intended for developers, which will go into much greater detail and will display real code examples.

Let’s Start At The Very Beginning

Before we begin discussing functional programming, let’s review the origins of computers and conventional programming. Note: I’ll be using the term “conventional programming” to refer to any language that isn’t functional.

Alan Turing

The first computer concept appeared in the 1930’s, when British mathematician Alan Turing conceived the idea. Initially, Turing’s concept was entirely hypothetical, however he would later go on to lead the project to build the first computers during World War II.

At the same time computer hardware was invented, developers were simultaneously taught how to program it. This is because the hardware designers created an instruction set, which defined the operations the computer could perform. These instructions included tasks such as adding two numbers, comparing two numbers, or jumping to a different instruction. A program is simply a series of these instructions, and this type of programming is called machine code.

An Alternative To Machine Code

The problem with machine code is that your code often has nothing to do with the content of your program. For example, right now your web browser is showing you a blog article. But, if you were to look at your browser’s machine code, you would see many instructions like adding and comparing, and it would be extremely difficult to figure out the purpose behind the instructions. Needless to say, writing code in this style is very difficult.

The solution we’ve come up with is creating high-level programming languages. Using a high-level language, developers don’t have to think about individual machine instructions like adding or comparing. Your web browser was actually written in a high-level language, so the developers were able to think in terms of real-world concepts, such as downloading files or displaying text and images on the screen.

Developers use programs called compilers to translate our high-level code (the source language) into lower-level machine code (the target language). This translation of our source code creates executable operations, so we can actually run our programs.

What Is A Function?

Functions are simply blocks of code that take input and return output. For example, a function might accept two numbers as input, and give their sum as output. It’s important that we make this distinction, seeing them as input and output rather than merely adding two numbers together. Functions actually existed before computers — mathematicians had already conceived of them. However, one mathematician made use of functions in a radically new way.

Alonso Church

Around the same time that Turing first conceived of computers, American mathematician Alonzo Church wrote a paper about a new concept he called Lambda Calculus. Lambda Calculus is a formal system of mathematical logic that defines all mathematics as functions. This includes the parts of mathematics we need for computers: numbers and their operators (+, -, etc.), Boolean values (true/false) and their operators (and, or, not).

Functional programming was born when Turing decided to study under Church for his PhD. Turing proved that his hypothetical computers were founded on the same principles as Church’s Lambda Calculus. This meant it was possible to compile Lambda Calculus’s into machine code. Essentially, it proved that functional programming could actually be computed by his machine.

Alan Turing and colleagues work on the Ferranti Mark I Computer in 1951

What’s next?

In Part II, we’ll dive deeper into the pros and cons of Functional Programming. We’ll also look at the differences between functional and conventional languages.

--

--

Tech At Tommy
techattommy

Discussing tech culture, development, innovation and design at Tommy Hilfiger