Delving into Paradigms

Ian CawoodIan Cawood
3 min read

I won't go too much into the theory here because there are CS courses available online that cover these topics. However, here is a nice video on imperative vs functional programming. Mostly, I will focus on what I've learned in the course so far (imperative, object-oriented, and functional). I also will not claim that there is a best programming paradigm but will admit that I have a bias towards functional programming.

During the courses, I learned all three paradigms in Python3, even though it is not that well suited for functional programming. If you'd like to learn functional programming in a nice environment, I would suggest Elixir, and if you'd like to learn a "purer" functional language (and inflict some emotional damage), you can always try Haskell.

Imperative

I'll explain as simply as possible how I understand imperative programming. To be honest, the course goes through a subset of imperative programming in the form of procedural programming, but they both satisfy these conditions:

  • Use statements that change the program's state.

  • The developer describes how the program should execute with code.

One of the most popular imperative paradigms is procedural. Procedural code follows a recipe-like flow and is popular for algorithmic programming. Hence, it is used a lot for machine learning applications (this is why Python and R are used in machine learning).

Object Oriented

The object-oriented paradigm works well in combination with other paradigms like imperative, procedural, and functional. I'm not sure if a pure object-oriented language exists since the imperative paradigm is almost required for object-oriented to work. Here are a couple of important aspects of the object-oriented paradigm:

  • Objects consist of data (in the form of attributes) and code (in the form of methods/procedures). Objects interact with each other and can inherit behavior from each other.

  • Side effects are built into the core design of objects.

  • Many/most of the widely used languages today support object-oriented paradigms (Python, Java, C#, C++, TypeScript).

Functional

With its design firmly rooted in academia, functional programming has a special place for anyone with a mathematical background. This is the only declarative paradigm we are looking at here. It focuses more on describing the logic of the end result rather than defining the program step by step as in imperative programming. Functional paradigms have these attributes:

  • Functions are first-class citizens (meaning they can be combined, passed around as arguments, and returned from other functions).

  • Functions minimize or eliminate side effects.

  • Focuses on composing smaller functions together to achieve complex data manipulation, which makes it very testable.

Conclusion

There really is no paradigm that can solve all your problems, which is why most languages are multi-paradigm. This should be a good indication that there is no one paradigm that can solve all your problems (well, technically you can, but only if you want more stress). Hopefully, this gives a nice overview with follow-up articles showing what kind of problems we can solve with these paradigms.

0
Subscribe to my newsletter

Read articles from Ian Cawood directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ian Cawood
Ian Cawood