Transcript
A (0:01)
Welcome to Co Recursive where we bring you discussions with thought leaders in the world of software development. I am Adam. Your host Runar Bijarnason has been exploring how writing in a functional style increases modularity and compositionality of software for many years. He is the co author of Functional Programming in Scala, a book that teaches these principles using the Scala programming language. It is a very challenging, yet very rewarding book, sometimes referred to simply as the red book. In this interview, Runar explains how writing in a functional style involves limiting side effects, avoiding exceptions and using higher order abstractions. Writing in this style places constraints on what a module in a software system can do. But by constraining modules in this way, the software modules themselves become endlessly composable. Enjoy. Runar Bijarnason is an engineer at Tokt. He is the co author of Functional Programming in Scala. Runar, welcome to the show.
B (1:12)
Thank you.
A (1:13)
Your book details. Your book is about purely functional programming and how it leads to more modular software. Before we get into specifics, what is purely functional programming?
B (1:28)
Well, purely functional programming is programming with functions only. So when I say functions, I mean mathematical functions. So function just takes an input and produces an output and doesn't do anything else. And then purely functional programming is purely programming with such functions.
A (1:55)
So there is no side effects in a mathematical function. Like a mathematical function cannot write to disk.
B (2:04)
Right.
A (2:04)
For instance.
B (2:05)
Exactly. So in functional programming, instead of having a function write to disk, the function returns a little program that requests of the caller or instructs the caller that something might need to happen, like writing to disk. And then it's up to the caller to pass that back to the runtime environment to have that actually happen.
A (2:31)
What problem does functional programming solve?
B (2:37)
Well, functional programming solves the problem of modularity and compositionality. So the sort of the superpower of functions is that they compose. So if you have a function that takes some type A and reduces, produces some type B, and you can always compose that with some function that takes that type B and produces some other type C. And then you have a composite function from A to C and that will always work. And since there are no side effects, it can never crash or go wrong.
