
About programming paradigms
Before we dive into this chapter, let's discuss a bit about programming paradigms.
Bluntly put, programming paradigms are different ways to express what a program should do. Paradigms have a very important influence over many aspects of the code you write, regarding maintainability, readability, performance, and so on.
The classic paradigms are the imperative/procedural ones that focus purely on the logical sequence of operations to perform and organize the code in groups of procedures that modify the state. The C programming language is a great example of a procedural/imperative programming language.
Another hugely popular programming paradigm in the industry nowadays is the functional programming (FP) one, which is declarative and focuses on the desired outcomes. With FP, you declare a series of functions to apply in order to reach the results.
Finally, the programming paradigm that we will explore a bit in this chapter is the OOP one. With the OOP paradigm, you focus mainly on how the code is organized and structured, regrouping code into logical units. With OOP, the state and the code, which influences the state, are both grouped together. OOP helps to create more understandable code by abstracting elements and by clearly defining the business domain concepts. Java, C#, C++, TypeScript, Python, and others support this approach.
Check out the following article if you want to read more about programming paradigms: http://cs.lmu.edu/~ray/notes/paradigms.
In the previous chapter, we mainly used imperative programming and a tiny bit of functional programming (for example, the forEach and filter functions combined with lambda expressions). In the rest of this book, we will continually mix paradigms, depending on the context. Each paradigm has its own benefits, depending on the situation.
Finally, as we will see in this chapter, the best way to define the domain model of your applications is to use OOP, as this is where it can bring the most value, by making the code clearer and more readable.