Three paradigms

Hello, Habr!



I bring to your attention a translation of the article “ Three Paradigms ” by Robert C. Martin (Uncle Bob).



image






Over the past 40 years, hardware technologies have increased the computing power of our devices by more than twenty orders of magnitude. Now we play Angry Birds on our phones, which have the processing power of a freon-cooled supercomputer of the 70s of the last century.



But over the same 40 years, software technology has not changed much. In the end, we still apply the if, while loops, and assignment operators that we used back in the 60s. If I took a programmer from 1960 and brought him here so that he could sit at my laptop and write code, it would take him 24 hours to recover from the shock, but he could write this code. The principles have not changed so much.



In the process of writing programs, three things have changed. I'm not talking about hardware, not about computer speed, and not about the incredible tools that we have. I mean the code itself. Three things have changed in the code. You can call them paradigms. And they were all “discovered” over one decade more than 40 years ago.



* 1968 - Structural programming . Edsger Dijkstra wrote his article: “On the dangers of the Go To operator” and a number of other documents and articles proposing to abandon the unbridled Go To approach, replacing it with such tools as if / then / else and while loops.



* 1966 - Object-oriented programming . Ole-Johan Dahl and Kristen Nyugor , studying the Algol language, “Discover” objects and create the first object-oriented language, Simula-67. Despite the fact that this achievement has many prospects, it has not brought any new features to our code. In addition, it removed one. After all, with the advent of polymorphism, the need for pointers to functions disappeared, but actually disappeared.



* 1957 - Functional programming . John McCarthy creates Lisp, the first functional language. Lisp was based on lambda calculus created by Alonzo Church in the 30s. Although there are many prospects for functional programming, there is one huge limitation in all functional programs. They do not use assignment.



Three paradigms. Three limitations. Structural programming sets the rules for direct control transfer. Object-oriented programming introduces rules for the indirect transfer of control. Functional programming introduces restrictions on assignment. All of these paradigms have taken away something. None of them added any new features. Each of them has increased requirements and reduced opportunities.



Can we create another paradigm? Is there anything else that can be removed?



For 40 years there has been no new paradigm, so perhaps this is a good sign that there is nothing more to look for.



Should we use all of these paradigms, or can we choose?



Over time, we decided to implement them. The introduction of the first structured programming was made possible thanks to the abolition of the Go To principle (as Dijkstra recommended in his article). OOP has been successfully implemented by replacing pointers with functions in our modern languages ​​using polymorphism (e.g. Java, C #, Ruby). Therefore, at least for these two, the answer to this question is that we MUST use them. All other options were excluded or at least severely limited.



But what about functional programming? Should we use languages ​​that do not have an assignment operator? Maybe yes! We are already writing code that should work well on several cores, and these cores multiply like rabbits. My laptop has 4 cores. My next one will most likely have 8. The one after 16. How are you going to write reliable code with 4096 processors fighting for the right to access the bus?

We can hardly get two parallel threads to work, not to mention 2 ^ n processors.



Why is functional programming an important part of solving this problem? Because such programs do not use assignment, which means that they do not have side effects and, therefore, do not have associated problems with updatability - at least that is the theory.



We'll talk more about functional programming in future blogs. What strikes me in the three paradigms mentioned above is their dates. They are ancient, almost older than me. And since I turned 16, 42 years ago, there have been no new ones.



All Articles