Which programming paradigm is best?

Programming Answer

Click here to type your answer

Safarov answered

There are many programming paradigms I know, but there isn't exact number on which programmers agree, a lot of groupings exist. I would say following are programming paradigms: Assembly, Procedural, Object Oriented Programming (OOP), Functional and Concurrent programming paradigm. Sometimes people don't count concurrent programming as programming paradigm.

Let's start with Assembly - assembly is paradigm for exact set of instructions running. You can write functions but essentially program executes linearly, if you want to write some logic and execute different command or call function you have only "GOTO" option, there isn't "while", "for" concepts. Also in assembly paradigm you have to tell computer to move, load, get data from AL, registers or memory - it's similar to machine language.

If you take a look at Procedural paradigm, I would explain like this: We have many encapsulated functions - that can be called from main function or other procedures. First programming language i  have learnt (when I was 10 years old) was Basic, then Pascal and C languages later years. These languages doesn't have classes, but more control over memory managment. Still using procedure paradigm - C language to program micro controllers.

Also there is OOP paradigm, here instead of calling functions directly, we group then inside class, create and object based on that class and call function of object. It sounds like extra work, but doing that saves a lot of time - when developing bigger and scalable projects. Here we think all functionality as if they were part of real world. If there is an car, it has 4 wheels, it can turn write, turn left, move .. etc. Then using blueprint of that car we can create 2 more classes - gasoline car and electric car. We don't need to change any functionality of base car, we just need extend car class and add engine function to each extended car. First OOP language I have learnt was Delphi - it was same as Pascal (procedural language), and supported classes. Similarly I have learnt C++, which is OOP version of C language. Later I have learnt many languages that support OOP like  Java, Actionscript 3, Javascript (Typescript), PHP (last versions support classes) etc.

Functional programming is old paradigm, but lately we see more oop languages embracing it's concepts. Main difference between imperative paradigms (prodecural, oop) is functional paradigm doesn't have states. So if we call same procedural function we can get another result each time, because it can have some values from global state. Similarly in the oop paradigm we can call same function and get different result becuase we have properties, each object can have different property value, or we can manipulate that value each time we call function, but in functional programming we have same result each time we call function. I have heard about functional languages like Haskel, List and Scheme, but didn't use them. But have used some functional paradigm concepts. For example i use to path functions as a value in Javascript and Actionscript, especially with frameworks like Angular and NodeJS. Also starting with Java 8 we have lambda expressions like map, filter in Java - I really like the simplicity there.

The last one in my list is Concurrent programming paradigm, it's a little bit different from others, because here we program threads that runs in parallel. It's really useful when we program network applications, that should act as a separate program (thread), wait until it gets processor time and run what it needs to complete. It's really useful when we program server that creates threads for each task or group user interactions together (for example in a game). But it has one main problem, when 2 threads want to manipulate same resource at the same time there can be a incorrect data or deadlock. Because of that we have to decide where we should use that paradigm and create correct transaction models. I have used this paradigm only with Java, but other languages like C, C++, C# etc support this.

There is another question which paradigm is best? - there isn't any clear answer to that question, if you program just uses concrete set of steps you can use assembly (if you need state as well procedural), if your programs has 100% real world analogy - then answer is oop. But if you need to program some abstract things like validation, transaction, event handling or you need to chain functions we should use functional paradigm. If you need program that runs in parallel or some tasks that should be run periodically without stopping main thread from execution, the answer is concurrent programming paradigm.

0 points