Differences and pros and cons of functional programming and object-oriented programming-object-oriented programming

Source: Internet
Author: User
Tags inheritance

What is it
Before describing the difference and pros and cons, briefly introduce both.
Functional programming, as the name suggests, this kind of programming is the function of thinking as the core, in this thinking angle to think about the problem. The most important foundation of this programming is the lambda calculus, which accepts functions as inputs and outputs.
Object-oriented programming, which is the problem of the object as a property of the object and the behavior of the composition. Based on the concept of object, the class is used as the template of object, and the class and inheritance are used as the structure mechanism and object as the center to think and solve the problem.

Advantages
Functional programming: Support for closures and high-order functions, closures are an object that functions as a function and can be manipulated as objects, while higher-order functions can be programmed with another function as an input value. Supports lazy computing, which can be evaluated at a time when the evaluation requires an expression, rather than being fixed on a variable. It is also possible to use recursion as a control process. The code that is programmed by functional programming is relatively much less and more concise.
Object-Oriented Programming: Object-oriented has three main characteristics, namely encapsulation, inheritance and polymorphism. The description of the class shows the encapsulation, class as an object template, contains private and public data, encapsulation performance makes the data more security depends on the characteristics of the class, so that users can only see the external characteristics of objects, can not see the intrinsic properties of objects, users can only access public data can not directly access to private data. The derivation of a class shows inheritance, which is the mechanism by which the subclass shares the parent class, but because of encapsulation, inheritance is limited to the inheritance of the public data (as well as the inheritance of protecting the data), and the subclass can also be derived while inheriting. Polymorphism refers to the polymorphism of the behavior of the object based on the received information, and different objects receive the same information to form many kinds of behaviors.

Disadvantages
Functional programming: All data can not be changed, seriously occupy the running resources, resulting in the running speed is not fast enough.
Object-oriented programming: A lot of unwanted code is generated to write reusable code, and many people object oriented to object-oriented causes code to cause late maintenance a lot of trouble.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.