Functional Programming and SOLID

Clean Code, Episode 58

By Robert C. Martin

73 minMar 2019

Fifty-Eight. 58 is 2*29 and is the sum of the first seven prime numbers: 2+3+5+7+11+13+17. 58 is the year that Sputnik was launched. "58 is like the luckiest number ever." according to Patrick on the Sponge Bob show.

And...Episode 58 is where we talk about the SOLID principles in Functional Programs.


In the last episode, Episode 57 (which is 3*19 and the atomic number of Lanthanum (not to be confused with gold-pressed Latinum)) I told you we were done with Starwars. I lied. Well, no, I didn't exactly lie. I was wrong, but I didn't know it at the time.

You see, at the time I knew I wanted to do an episode on the SOLID principles in functional programming. I just didn't know I was going to be using Starwars as the example. But then, as I started writing the episode, it became clear to me that there were loads and loads of SOLID principle conformance and violation in Starwars.

Anyway, Starwars it is. One more time. And this time we're going to look at it from the point of view of:

  • SRP - The Single Responsibility Principle,
  • OCP - The Open-Closed Principle,
  • LSP - The Liskov Substitution Principle,
  • ISP - The Interface Segregation Principle, and
  • DIP - The Dependency Inversion Principle.

As an aside, did you know that twenty years ago there was a guy on USENET who accused me of being a racist for using the word "segregation" in the ISP?