Posts

Showing posts from April, 2023

More Performant, Testable Code with Functional Programming. (FP language optional!)

Image
Valve Software , CC BY-SA 4.0 , via Wikimedia Commons Is functional programming worth learning? Functional programming can make code in your favorite language more succinct, testable, performant, and maintainable. (Functional programming language optional!) First, let’s quickly define functional programming (FP): A programming paradigm that avoids mutation and side effects. Notice FP does not require a functional programming language. FP is a way of thinking: you can do FP in your favorite languages like Python, JavaScript, Java, C, etc… (Of course, languages designed for FP make it easier with built-ins like first-class functions and immutable data structures.) So how does avoiding mutation and side-effects improve your code? FP results in more performant code. Functions without side-effects (interactions with external mutable state) are trivial to parallelize. Reading/writing to a global variable results in side-effects. So does all I/O: logging to the