What are arguments against object-oriented programming
Object-oriented vs. functional programming on the web
Many web applications are implemented in an object-oriented manner today, but functional programming is experiencing a revival. It is not uncommon for a dispute to break out in the programming paradigm: some swear by functional programming, others by object-oriented programming. The truth is probably in between. We show the differences and tell you which paradigm is best used when.
For a better understanding, we start with the presentation of object-oriented and functional programming.
object oriented programing
In object-oriented programming (OOP), the software architecture strives to represent reality. So-called classes encapsulate data and implement functions for data manipulation. Today it is considered by many to be state of the art, especially in connection with design patterns.
Many OO implementations maintain the principle of secrecy, which is also known as information hiding. In this programming paradigm, variables are encapsulated in objects. In accordance with the principle of secrecy, variables are usually accessed using getter methods and setter methods. The programming style is often similar to the imperative / procedural style.
The central property of object-oriented software is reusability. Class properties can be used in new implementations through inheritance. Changes to the original class are made by overloading and overwriting functions of the parent class. The addition of interfaces and additional methods in the child class is also possible within the scope of inheritance.
Example of a PHP class:
The data is encapsulated in the class. This delivers different results for both calls. The change is brought about by calling the function.
Functional programming is assigned to declarative programming. This programming paradigm focuses on functions, it is based on the lambda calculus. Functional programs are stateless and data (variables) cannot be changed. That includes advantages. The functional programming is well equipped for parallelization and is easy to test. It is even possible to verify the stateless functions.
The functional code is usually easy to understand. The functions are clear thanks to statelessness and unchangeable data. The design phase is also easy.
Example code for an anonymous (stateless) function in PHP:
The function can be called as often as required. The output depends on the input values, but is deterministic. The transferred objects are not modified by the anonymous function. This follows the principle of functional programming.
Another classic example of functional programming is the recursive calculation of the factorial:
When does which programming paradigm make sense?
There is no all-inclusive winner. Functional programming shows its strengths when testable and verifiable code is required. Functional programming is also well suited for code that can be easily parallelized. The examples also show that the mostly imperative object-oriented programming can easily be combined with the functional.
The recursive programming method of functional programming, as we see it in the third example, is dangerous: the data and the program code are loaded onto the stack for each recursion. Comprehensive operations that, for example, establish connections to other servers or databases and call up large amounts of data can quickly become memory hogs. Then there is a risk of memory overflows and program errors.
You can find more information and examples on the trend of functional programming in web applications under the following links:
- How do I combine this sentence
- How many years are there between reincarnations?
- Can trans women produce semen
- The FCC is constitutional
- What is only famous in Churu
- Regret joining a soldier why
- What do you mean by entrepreneurship and innovation
- Have Pisces ascendant have budhaditya yoga
- What is the importance of studying sociology
- What is the difference between light fear and severe fear?
- Can destroy a muon with a positron
- What do Apple employees think of Android
- Patella is the largest sesame bone
- What are some dressing tips for kids
- Should I code professionally to become a hacker
- Coastal regions have a continental climate
- Aromatherapy changes your mood
- Are people born well? Does that matter
- What are software robots
- What is sensor technology in the IoT
- Know everything about Google Ads
- Gasoline can be stored indefinitely
- Drinking ORS makes you less thirsty
- Why is Microsoft killing Hotmail