Given the same inputs, a pure function should always return a value and never modify state through the use of class attributes. It is a declarative programming paradigm in which function definitions are trees of expressions that map values to other values, rather than a sequence of imperative statements which update the running state of the program.” What does that mean for the average developer who’s used to the more common object oriented programming model (OOP)?įirstly, programs are made “by applying and composing functions”, so in our slot machine, we’ll need to make sure that we use as many pure functions as possible, a concept known as referential transparency. When the program is run, the output looks like this:Īccording to Wikipedia, “Functional programming is a programming paradigm where programs are constructed by applying and composing functions. You can view the full gist here, but I’ll also explain some of the logic used when developing from a functional perspective. Since this involves Python, as a way to brush up on my Python I decided to build a simple, single reel slot machine using a functional programming paradigm. Recently I’ve been helping a friend with some Flask apps.