Programming paradigm, Programmer's programming worldview

Source: Internet
Author: User

Programming paradigm, Programmer's programming worldview

The importance of programming paradigms

On June 17, 2013 that day has been written 14,796 times to read the Thank you reference or the original server has spent a total of 19.580 MS 2 database queries, and strive to provide you with this page. Try reading mode? I'd like to hear your suggestions.

The programming paradigm (programming Paradigm) is a typical programming style of a programming language or a programming approach. With the development of programming methodology and software engineering, especially the popularization of OO ideas, the terms of paradigm (PARADIGM) and programming paradigm are appearing in front of people. Object-oriented Programming (OOP) is often hailed as a revolutionary idea, because it differs from other programming paradigms. The programming paradigm is perhaps the most important term to understand when learning any programming language.

After Thomas Kuhn put forward the paradigm of "scientific Revolution", Robert Floyd used the term "programming paradigm" in the 1979 Turing Award presentation. The programming paradigm typically consists of three aspects, with OOP as an example:

    1. The logical system of discipline--rule paradigm: such as Class/object, inheritance, dynamic binding, method rewriting, object substitution and so on.
    2. Psychological cognition factor--psychological paradigm: According to the view of the father Alan Kay of object-oriented programming, "calculation is simulation". OO paradigm attaches great importance to the value of metaphor (metaphor) and simulates nature in a natural way by personification.
    3. Natural View/World Outlook-concept paradigm: Emphasizing the organization of the program, depending on the program as a loosely-coupled set of objects/classes, the inheritance mechanism organizes the classes into a hierarchical structure, and the program runs as a dialogue between the objects that serve each other.

Simply put, the programming paradigm is the view that programmers should have in view of the program.

To further deepen our understanding of the programming paradigm, here are some of the most common programming paradigms.

Again, it is important to note that the programming paradigm is a classification of programming languages and is not intended for a programming language. In the case of programming languages, a programming language can also be used in a variety of programming paradigms.

Procedural (imperative) programming

Procedural programming, also known as imperative programming, should be the most primitive and a traditional way of programming that we are most familiar with. In essence, it is the abstraction of the operating mechanism of "Von Neumann Machine", which is based on the sequential arrangement of computer instructions.

(That is, the procedural language simulates the system structure of a computer machine, not the individual abilities and tendencies of a language-based user.) We should be very clear on this point, such as: We have used the first MCU assembly language. )

The steps for procedural programming are:

First, we must abstract the solution of the problem to be solved as a series of conceptualized steps. These steps are then programmatically translated into program instruction sets (algorithms), which are arranged in a certain order to illustrate how to perform a task or solve a problem. This means that the programmer has to know what the program is going to do and tell the computer how to do the required calculations, including every detail operation. In short, it is to treat a computer as a device that finish obey commands.

Therefore, in the process of programming, it is a key step to standardize and abstract the problem to solve the problem. Secondly, it is the correct solution to write the specific algorithm and complete the corresponding algorithm implementation problem. Of course, the ability of programmers to deal with the abstraction of a problem is also a very important factor, but it has nothing to do with programming languages.

Program Flowchart is an effective assistant method for programming of process language.

Although there are many existing computer programming languages, all programming languages that support the process programming paradigm are summed up in a procedural programming language. For example, machine language, assembly language, BASIC, COBOL, C, FORTRAN, language, and many other third-generation programming languages are summarized into the process of language.

The procedural language is particularly suited to solving linear (or step-by-step) algorithmic problems. It emphasizes the design approach of "top-down" and "excellence". This approach is very similar to our work and lifestyle, because our daily activities are carried out in a sequential order.

Procedural languages tend to develop programs that run faster and have higher utilization of system resources. The procedural language is very flexible and powerful, and there are a number of classic application examples that allow programmers to use it to solve a variety of problems.

The disadvantage of a procedural language is that it is not suitable for solving certain kinds of problems, such as unstructured problems with complex algorithms. The problem is that the procedural language must explain an algorithm in detail and include the order in which the instructions or statements are executed. In fact, it is extremely difficult to give detailed algorithms to unstructured problems with complex algorithms.

A widely contentious and controversial place is the unconditional branch, or Goto statement, which is part of most procedural programming languages, and opponents claim that a goto statement can be misused indefinitely; it gives the program a chance to create confusion. The current consensus is that it should be kept in most languages, and that it should be minimized in terms of the risks it has.

Event-driven programming

In fact, event-driven programming has been applied to program design long before the graphical user interface (GUI) appears, but only when the graphical user interface is widely popular, it gradually evolved into a widely used programming mode.

In procedural design, the code itself gives the order in which the program executes, although the order of execution may be affected by the program's input data.

In an event-driven program design, many parts of the program may be executed at a completely unpredictable time. Often, the execution of these programs is motivated by the interaction of the user with the program being executed.

    • event . is to inform that a particular event has occurred (the occurrence is random).
    • events and polling . The conduct of polling is constantly observed and judged, and is an endless form of behavior. And the event is quietly waiting for things to happen. In fact, before Windows appears, PC applications that use the mouse input character mode must perform serial polling and in this way query and respond to different user exercises.
    • event handler . is a piece of program code that executes when a response is made to an event. The event handler enables the program to respond to the user's behavior.

Event drivers are often used for user interaction with the program, interacting interactively through a graphical user interface (mouse, keyboard, touchpad). Of course, it can also be used for exception handling and responding to user-defined events, and so on.

Event exception handling is more complex than user interaction.

Event-driven is not confined to GUI programming applications only. But we also need to consider more practical issues such as event definition, event triggering, event transformation, event merging, event queuing, event dispatch, event handling, events, and so on.

In fact, so far, we have not found the language for pure event-driven programming and a similar development environment. All event-driven data is based on GUI events.

The event-driven programming languages are: VB, C #, Java (GUI of Java swing), etc. Most of the events they involve are GUI events.

Object-Oriented Programming

A procedural paradigm requires programmers to look at each problem with a step-by-step algorithm. It is clear that not every problem fits into this process of thinking. This has led to the emergence of other program design paradigms, including the object-oriented programming paradigm we are introducing now.

The object-oriented programming pattern has been in the more than 20 years, after the development of these years, its design ideas and design patterns have steadily entered the mainstream of programming language. The top three Java, C, C + +, Java and C + + are all object-oriented programming languages from the Tiobe programming Community2010 Year November programming language rankings.

Object-oriented programming includes three basic concepts: encapsulation, inheritance, polymorphism. Object-oriented programming language supports object-oriented design paradigm through classes, methods, objects, and message passing.

1. Objects

Everything is the object of the world.

The abstract mechanism of object-oriented program design is to abstract the problem to be solved as an object in object-oriented program. Use encapsulation to make each object have an individual identity. The program is a pile of objects, passing through the message, requesting other objects to work.

2. Class

Each object is an entity in its class.

Birds of a feather--that is, the class is a collection of similar objects. The object in the class can accept the same message. In other words: The class contains and describes a set of objects that have common attributes (data elements) and common behaviors (functions).

For example: apples, pears, oranges and other objects belong to the fruit category.

3. Encapsulation

Encapsulation (sometimes referred to as information hiding) is the process of combining data and behavior in a package and hiding the data from the user of the object. Information hiding is the basic principle of object-oriented programming, and encapsulation is a way to realize this principle.

Encapsulation enables objects to present a "black box" feature, which is a key step in the reuse and reliability of objects.

4. Interface

Each object has an interface. An interface is not a class, but a set of specifications for a class that conforms to the requirements of the interface. The interface describes what the class should do but does not specify how it should be done. A class can have one or more interfaces.

5. Methods

method determines what kind of message an object can accept. Object-oriented design is sometimes simply summed up as "sending messages to objects".

6. Inheritance

The idea of inheritance is to allow new classes to be built on the basis of existing classes. A subclass can inherit all members of the parent class, including properties and methods.

The primary role of inheritance is to accomplish code reuse by implementing inheritance, and the completion of code reuse through interface inheritance. Inheritance is a technique of specification, not a technique of implementation.

7. polymorphic

Polymorphism provides "interface and implementation separation". Polymorphism can not only improve the structure and readability of the program, but also develop the "expandable" program.

Inheritance is the basis of polymorphism. Polymorphism is the purpose of inheritance.

It can enhance the simplicity, flexibility, maintainability, reusability and Expansibility of the program by using polymorphism based on class inheritance, multi-state based on interface inheritance, and polymorphism based on template.

The object-oriented technology, on the one hand, draws on the thinking way of philosophy, psychology and biology, on the other hand, it is based on other programming techniques and is the natural product of previous programming thought.

If the structural software design is to apply the functional programming technology to the command language programming, object-oriented programming is just another way to apply the functional model to the imperative program, at this point, the module progresses to the object, the process is holed up to the class member method. Many of the technologies of OOP--abstract data types, information hiding, interface and implementation separation, object generation, messaging, and so on--are many things that are owned by structured software design or appear separately in other programming languages. But only in the object-oriented language, they appear together, in a unique way of cooperation to cooperate and complement each other.

Programming paradigm, Programmer's programming worldview

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.