At the end of last year, I’ve been introduced to Functional Programming (FP) by a former collegue. He told me that it forces you to think in a different way, when writing code. Curious as I was, I decided to take the Functional Programming course on Coursera, to learn more about it.
The teacher is Martin Odersky (designer of the Scala programming language), who gives several video lectures every week. What takes most of my time are the weekly assignments. Usually I solve the problems with pen and paper, and write the actual code afterwards.
What is Functional Programming
There are three main programming paradigms. A paradigm describes distinct concepts or thought patterns in some scientific discipline. I’ll briefly describe two of them below.
Imperative programming
You probably know imperative programming from languages such as PHP, Python, Java…
These are about:
- modifying mutable variables
- using assignments
- control structures such as if-then-else, loops, break, continue, return
Functional programming
In a restricted sense, functional programming means programming without mutable variables, assignments, loops and other imperative control structures.
In a wider sense, functional programmingmeans focusing on the functions. Functions can be values that are produced, consumed, and composed. All this becomes easier in a functional language.
FP concepts in Python
As a web developer, I’ve spend a lot of time working with PHP, JavaScript etc. But ever since I’ve started to work with Python, I’ve got in touch with list comprehension, generators and iterators. These are all concepts of Functional Programming.
It provides new ways to work with data, which results in more elegant and compact code, which in turn is better readable.
Personal experience
With what I’ve learned, I found out that I could apply these FP concepts throughout most of my code. Still four weeks to go on the course, but the more I learn about it, the more it fascinates me.
Learning Functional Programming really feels like a great step forward to me.
Further reference
Progfun
The Functional Programming course on CourseraWhy Functional Programming Matters
A paper by John Hughes from 1984Learn Haskell
Great introduction into Haskell, a functional programming language