CodeForWar

Blab on Technology

Pure Functions

March 19, 2025 | Categories: programming

Pure Functions and their readability. I am currently refreshing myself on Functional Programming with Scala and I have to say that I still can't figure out why Pure Functions are not adopted more.

Maybe it comes from working so much in the C programming language, but looking at a function's type signatures and getting a pretty good clue of what the function does goes far behind my original idea of "Source Code doesn't lie". In OOP design you often have to go to the function to get a better idea of what's going on with that function, but with a promise of Pure functional programming you get most of that purely from it's Type System.

For example:
I can get a good idea of what this function does simply by it's Type System. Meaning what parameter type it takes and what parameter it returns.


One thing to notice about pure functions is that they _always_ have input parameters, and they never return Unit.


Special thanks to Alvin Alexander and his content at Learn Scala. It's been a great resource for a refresher and just checking out what he's been doing for the Scala community in general. Please make sure to check him out.