Imperative Programming vs Functional Programming

While I was first learning how to build web apps, I was learning object oriented design using Ruby. This programming paradigm was easy for me to grasp. I took real world models and replicated these situations via code. For example, my first Rails app was a Yoga class tracker. Through my code I demonstrated that a yoga class has a class plan, and belongs to both a client and a teacher. This app also exemplified Imperative programming. When I first started to learn JavaScript, I first learned the language through the lens of imperative programming. Imperative programming is writing a simple script “do this then this”. Imperative programming consists of loops and conditional statements

Alternatively, functional programming deals with how inputs are transformed into outputs. Functional programming is pure meaning the output only depends on the input of the function. Therefore, functional programming does not have side effects. Also, functional programming does not have a “state” like imperative programming. For flow control, functional programming uses function calls and recursion.

The original inspiration for this blog post was to answer a question I had originally come up with. I wish I had a post like this when I first started to learn Functional Programming. Especially since I started to learn Functional Programming from the perspective of Imperative Programming.

Feel free to re-read this article as many times as you like. I re-read my resources repetitively to get clear about the differences between the two styles of programming.

Leave a Reply

Your email address will not be published. Required fields are marked *