On Lisp: Chapter3, Functional Programming

And we return to On Lisp for the next exciting instalment!

Chapter 3 gives us a quick introduction to Functional programming. This chapter is not full of code but uses a few functions to demonstrate the benefits of programming in a functional way.

I have been a convert for a while, even if pragmatism/performance means sometime it is better to with a different solution. Way back in my professional game dev days (PlayStation 2 days to date me) working on a sport game and being charged with helping figure out what animations to play (which various addjustments to their metadata) to contact with a ball at a given time and position it quickly became clear a functions approach was better for debugging. We would move the PC back to just before the call and run the query function again. This was written in C++, well closer to C rather than the modern C++ we have today.

So while I would say nothing is really new here, it is succinct and covers why you should prefer functional programming where possible. Improved code locality means ease of testing in interactive sessions.

He touches on the idea that we always need some side effects and there is a scale how bad certain side effects are. That is it is mostly harmless for a function to modify something that no one else owns.

Where Paul Graham excels is he presents all this information in one small chapter without it feeling dense. If this is your first contact with functional programming then to fully understanding or perhaps fully appreciate this chapter could take months. Although I would suggest moving on, writing code and then re-reading rather than sitting on a rock pondering this chapter. Unfortunately you need a bit of lisp to understand the examples properly so it is not for general reading :(

Finally something I had not appreciated it that Lisp is at it’s heart a pragmatic language with offers both imperative and functional styles of programming. Over the course of it’s history the preference for functional programming is because they found it lets them write programs faster. Particularly when combined with interactive development. If they had found imperative to be better for their use cases that would have been the approach they took. It is perhaps the long history of Lisp that had allowed the evolution to happen with in the language by the early 1990’s.

My favourite quote is

Quote: “The character of an object is influenced by the elements from which it is made. A wooden building looks different from a stone one.”

I am really looking forward to the next chapter and honestly the rest of the book.


449 Words

2020-08-24 20:24 +0000