lunarised.com

Descent into Functional Programming

Ever since I learnt to program, I have been actively trying to push myself as hard as I can to understand the fundamentals of programming as well as I would ever need to. But recently, I’ve realized how much I just don’t understand, thanks to the brilliant discovery of functional programming.

What is functional programming?

If you are reading this, you 99% know what functional programming is, and why I might be drawn to it. But incase you live under a rock, or are just interested in reading some potentially wrong information, Functional Programming is a paradigm of programming that is based on the concept of composing mathematical functions to compute, as opposed to using state in other paradigms.

That’s probably wrong, but oh well…

Why is functional programming?

I am learning functional programming at the moment because of the famous computer science textbook, SICP or “Structure and Interpretation of Computer Programs”, which is a textbook from MIT, in which the reader learns plenty about Functional Programming, Computer science, and a programming language called Scheme. I have been struggling with this book for around 3 months now and have just breached the page 50 mark. There is a lot of information in it, and if you have any interest in computation, then I highly suggest giving it a flick through, and even making an attempt at getting through it, as i have found it to be an invaluable resource for learning functional programming.

Who is functional programming?

Functional programming as a paradigm can probably trace its roots back to Alonzo Church, and his lambda calculus, which was essentially a way of computing based on variable binding with functions.

What is functional programming (visually)

In Racket (A lisp based functional programming language), finding the max number of a pair looks like this

(define (maxNum a b)(
	if (> a b)
		a
		b))

versus this in Typescript

function maxNum(x: number, y: number): number{
  return (x > y)? x : y
}

You’ll notice that racket has a fair few brackets more than the typescript. Both of these functions are pure(ish) though so it’s hard to see a difference. I guess something worth mentioning, is in lisp langs, things inside ()’s are computed, like in mathematics, meaning you can choose in what order things are computed. Pretty Clever! Will post a bigger difference in a future post though!


Keep your realities separate...

lunarised_