Home Common Problem What are the multi-paradigm programming languages?

What are the multi-paradigm programming languages?

Dec 07, 2020 pm 02:25 PM
programming language multi-paradigm

Multi-paradigm programming languages ​​include: 1. Object-oriented programming, which improves the reusability, flexibility and scalability of software; 2. Functional programming, a programming paradigm that uses mathematical functions as the core programming language modeling ; 3. Generic programming provides a higher level of abstraction.

What are the multi-paradigm programming languages?

#The operating environment of this article: Windows 7 system, Dell G3 computer.

Multi-paradigm programming languages ​​are:

Summary:

This article mainly talks about three programming paradigms - object-oriented programming and functional programming , The concept of generic programming

Programming paradigm

The programming paradigm is the idea behind the programming language. Represents the program designer's view of how the program should be constructed and executed. Common programming paradigms include: procedural, object-oriented, functional, generic programming, etc.

Some programming languages ​​are specially designed for a specific paradigm. For example, C language is a procedural programming language; Smalltalk and Java are relatively pure object-oriented programming languages; Haskell is a purely functional programming language. In addition, the relationship between some programming languages ​​and programming paradigms is not one-to-one. For example, Python, Scala, and Groovy all support object-oriented and functional programming to a certain extent. C is a successful example of a multi-paradigm programming language. C supports the same procedural programming paradigm as the C language, and also supports the object-oriented programming paradigm. STL (Standard Template Library) enables C to have generic programming capabilities. Supporting multiple paradigms may be one of the reasons why C still has such a strong vitality to this day.

Swift is a typical multi-paradigm programming language, which supports object-oriented programming paradigm, functional programming paradigm, and generic programming. Swift's support for multiple programming paradigms is determined by its creation goals. The original intention of Swift was to provide a practical industrial language. It is different from academic programming languages ​​like Haskell that come from universities and research institutions. Apple had a clear business purpose when it launched Swift: Objective-C, the main programming language for Mac OS and iOS systems, has become obsolete. Swift will allow developers of Apple systems to have a more modern programming language, thereby promoting Apple The healthy development of the entire ecosystem.

The design and development of Swift all reflect the goal of "practical industrial language". This determines that Swift cannot do extreme language experiments. It needs to carefully seek breakthroughs based on facing reality rationally. This determines that Swift needs to inherit the historical legacy, take care of the practical needs of most programmers today, and at the same time develop towards the future.

1. Object-oriented - inheriting the legacy

Object-oriented programming uses objects as the basic unit of the program, encapsulating the program and data in it to improve the reusability of the software. Flexibility and scalability.

The core concept of object-oriented programming:

  • Polymorphism refers to different related classes generated by inheritance, whose objects will respond to the same message differently. Response;

  • Inheritance, in some cases, a class will have "subclasses". The subclass is more specific than the original class (called the parent class);

  • Encapsulation, object-oriented programming hides the specific execution steps of a certain method, instead using messages The delivery mechanism delivers messages to it.

In an object-oriented programming language, objects are used to build the basic unit of the program. Polymorphism provides higher abstraction capabilities, allowing us to design more general programs. Inheritance provides a way to reuse code. Encapsulation provides a more convenient and safer mechanism to use other code.

The working language of most programmers is still object-oriented programming language. Most popular modern programming languages ​​allow you to create objects. Software models are easy to build using object-oriented programming languages. Because objects are classes it seems easy to relate to all things and concepts in the real world. But programming practice shows that not everything becoming an object is a good thing. To give a lame example in Java: only objects can be passed into functions as parameters in Java (and of course primitive types). So in order to pass a function to another function, you need to wrap the function in an object, usually with an anonymous class, because this class has no other purpose, just to make Java's everything-object design happy.

Java has a pure object-oriented concept. From the beginning of its design, it was hoped to model the world with a pure object model in which everything is an object. But now, more and more non-object things have been added to Java. Closures were introduced to obtain first-level functions in functional programming; generics were introduced to obtain parameterized types. This may suggest that the world is so rich and diverse that modeling it using a single model will not be successful.

2. Functional programming - development

Functional programming is a programming paradigm that uses mathematical functions as the core programming language modeling. It treats computer operations as mathematical function calculations and avoids the use of program state and mutable objects.

There are two main ideas in functional programming:

  • Using functions as the core of programming language modeling;

  • Avoid state and mutability.

Functions are the cornerstone of functional programming. The code of a functional programming language is composed of functions. The process of writing a functional language is designing functions. Large-scale programs are composed of thousands of functions, and these functions must be combined efficiently. Functional programming languages ​​try to avoid states and mutable objects. The absence of mutable state makes functions in functional languages ​​pure functions. Pure functions are easier to modularize, easier to understand, and friendly to reuse.

Functional programming languages ​​have also produced some useful programming tools:

  • First-level functions, closures;

  • Curried function;

  • lazy evaluation.

These will be mentioned in subsequent chapters. These programming tools are increasingly appearing in other programming languages ​​as well.

Functional programming language is not young, its history is as long as object-oriented programming. LISP, created in 1958, is the oldest functional programming language. It is older than the C language. But it is only recently that functional programming ideas have gradually been taken seriously. Almost all newly invented programming languages ​​are more or less influenced by functional programming ideas. Python, Scala, Groovy, and Swift all have first-level functions and closures. This allows you to pass a function directly to another function, and the function can also be returned by another function in the form of a return value. The benefits of eliminating state and providing immutability are increasingly accepted. Scala, Groovy, and Swift all provide convenient methods for declaring immutable objects to support you in writing code that is closer to a functional style.

Functional programming language has its advantages and may become an important programming paradigm in the future. However, the importance of functional programming languages ​​may be more reflected in the development of other programming languages. In the future, it may be difficult for a programming language designed primarily with a functional programming paradigm to become a mainstream programming language. Programming languages ​​like Java that are built on a single programming paradigm (object-oriented) have little chance of becoming mainstream. The pursuit of a purely functional programming language like Haskell may be more of an academic language experiment.

Repeat the reasons mentioned in the previous section, the world is so rich and colorful, modeling the world using a single model will not succeed.

Object-oriented and functional programming

If we classify the currently popular languages ​​according to language paradigms. Supporting object-oriented programming languages ​​should be the longest queue. Most of the popular modern programming languages ​​are object-oriented, and they all allow you to create objects. But at the same time, you will find that several of the more popular programming languages, Python, Scala, and even Java, are more or less influenced by functional programming languages. They all introduce some functional programming concepts, allowing you to write functional-style code to a certain extent.

After getting familiar with object-oriented programming languages, when you come into contact with functional programming languages, you will often find it refreshing, and you may even vaguely feel that functional languages ​​are a good way to save the world. So should we completely switch to functional programming languages? Use Haskell to save the world.

After large-scale practice of object-oriented programming languages, we do have a deeper understanding of their shortcomings (for example, it is difficult to write software applications in a multi-threaded environment; inheritance is not a good method for code reuse). Functional languages ​​do have many advantages, some of which can solve the problems of object-oriented languages ​​(pure functions are very suitable for multi-threaded environments, pure functions are inherently modular, and are very friendly to code reuse). However, functional programming may also have certain problems. These problems may only be exposed after larger-scale industry practice. We have now established that modeling the world in terms of objects alone is difficult. Then modeling the world with mathematical models may not be any better. What is certain is that they all have their own areas and environments in which they excel. We still don't have a programming paradigm that can solve all problems.

The bigger reality is that countless companies have made huge investments in object-oriented programming languages. Even though object-oriented programming has exposed some problems, functional programming has shown many solutions to these problems. The advantages of the problem are that no prudent person will and cannot abandon object-oriented programming immediately and completely and comprehensively switch to functional programming languages.

The realistic choice is to support object-oriented programming and provide functional support at the same time. In this way, you can still use object-oriented methods in most places where you are comfortable with object-oriented. And where functional programming is suitable, and you have functional programming thinking and ability, you can still improve productivity using functional programming methods.

3. Generic programming-beautiful embellishment

Generic programming is another interesting topic. Generics provide a higher level of abstraction for programming languages, namely parameterized types. In other words, it is to abstract the type information in an algorithm or class that is originally specific to a certain type. This abstracted concept is a template in C's STL (Standard Template Library). STL demonstrated the power of generic programming and became a powerful weapon of C as soon as it appeared. In addition to C, programming languages ​​such as C#, Java, and Haskell have introduced the concept of generics.

Generic programming is a slightly more local concept, it only involves how to deal with types more abstractly, that is, parameterized types. This is not enough to support the core concepts of a language. We don't hear about a programming language being purely generic programming with no other programming paradigms. But precisely because generics do not change the core of the programming language, most of the time, they can be well integrated into other programming methods. Programming languages ​​with different styles such as C, Scala, and Haskell all support generics. Generic programming provides a higher level of abstraction, which means greater expressive power. This is a delicious accompaniment to most programming languages.

In Swift, generics are widely used, and many of the Swift standard libraries are built with generic code. For example, Swift’s array and dictionary types are both generic sets. Examples like this can be found everywhere in Swift.

Summary

In these series of articles, we will mainly use Swift as an example to explain the multi-paradigm programming language. This series of articles is divided into three parts to discuss the three programming paradigms supported by Swift:

  • Object-oriented programming paradigm

  • Functional programming paradigm

  • Generic Programming

For more related knowledge, please visit the FAQ column!

The above is the detailed content of What are the multi-paradigm programming languages?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei's official introductory tutorial for Cangjie programming language is released. Learn how to obtain the universal version SDK in one article Huawei's official introductory tutorial for Cangjie programming language is released. Learn how to obtain the universal version SDK in one article Jun 25, 2024 am 08:05 AM

According to news from this site on June 24, at the keynote speech of the HDC2024 Huawei Developer Conference on June 21, Gong Ti, President of Huawei Terminal BG Software Department, officially announced Huawei’s self-developed Cangjie programming language. This language has been developed for 5 years and is now available for developer preview. Huawei's official developer website has now launched the official introductory tutorial video of Cangjie programming language to facilitate developers to get started and understand it. This tutorial will take users to experience Cangjie, learn Cangjie, and apply Cangjie, including using Cangjie language to estimate pi, calculate the stem and branch rules for each month of 2024, see N ways of expressing binary trees in Cangjie language, and use enumeration types to implement Algebraic calculations, signal system simulation using interfaces and extensions, and new syntax using Cangjie macros, etc. This site has tutorial access address: ht

After 5 years of research and development, Huawei's next-generation programming language 'Cangjie” has officially launched its preview After 5 years of research and development, Huawei's next-generation programming language 'Cangjie” has officially launched its preview Jun 22, 2024 am 09:54 AM

This site reported on June 21 that at the HDC2024 Huawei Developer Conference this afternoon, Gong Ti, President of Huawei Terminal BG Software Department, officially announced Huawei’s self-developed Cangjie programming language and released a developer preview version of HarmonyOSNEXT Cangjie language. This is the first time Huawei has publicly released the Cangjie programming language. Gong Ti said: "In 2019, the Cangjie programming language project was born at Huawei. After 5 years of R&D accumulation and heavy R&D investment, it finally meets global developers today. Cangjie programming language integrates modern language features, comprehensive compilation optimization and Runtime implementation and out-of-the-box IDE tool chain support create a friendly development experience and excellent program performance for developers. "According to reports, Cangjie programming language is an all-scenario intelligence tool.

Huawei launches HarmonyOS NEXT Cangjie programming language developer preview beta recruitment Huawei launches HarmonyOS NEXT Cangjie programming language developer preview beta recruitment Jun 22, 2024 am 04:07 AM

According to news from this site on June 21, Huawei’s self-developed Cangjie programming language was officially unveiled today, and the official announced the launch of HarmonyOSNEXT Cangjie language developer preview version Beta recruitment. This upgrade is an early adopter upgrade to the developer preview version, which provides Cangjie language SDK, developer guides and related DevEcoStudio plug-ins for developers to use Cangjie language to develop, debug and run HarmonyOSNext applications. Registration period: June 21, 2024 - October 21, 2024 Application requirements: This HarmonyOSNEXT Cangjie Language Developer Preview Beta recruitment event is only open to the following developers: 1) Real names have been completed in the Huawei Developer Alliance Certification; 2) Complete H

Tianjin University and Beihang University are deeply involved in Huawei's 'Cangjie” project and launched the first AI agent programming framework 'Cangqiong” based on domestic programming languages. Tianjin University and Beihang University are deeply involved in Huawei's 'Cangjie” project and launched the first AI agent programming framework 'Cangqiong” based on domestic programming languages. Jun 23, 2024 am 08:37 AM

According to news from this site on June 22, Huawei yesterday introduced Huawei’s self-developed programming language-Cangjie to developers around the world. This is the first public appearance of Cangjie programming language. According to inquiries on this site, Tianjin University and Beijing University of Aeronautics and Astronautics were deeply involved in the research and development of Huawei’s “Cangjie”. Tianjin University: Cangjie Programming Language Compiler The software engineering team of the Department of Intelligence and Computing of Tianjin University joined hands with the Huawei Cangjie team to deeply participate in the quality assurance research of the Cangjie programming language compiler. According to reports, the Cangjie compiler is the basic software that is symbiotic with the Cangjie programming language. In the preparatory stage of the Cangjie programming language, a high-quality compiler that matches it became one of the core goals. As the Cangjie programming language evolves, the Cangjie compiler is constantly being upgraded and improved. In the past five years, Tianjin University

How to switch language in microsoft teams How to switch language in microsoft teams Feb 23, 2024 pm 09:00 PM

There are many languages ​​to choose from in Microsoft Teams, so how to switch languages? Users need to click the menu, then find Settings, select General there, then click Language, select the language and save it. This introduction to switching language methods can tell you the specific content. The following is a detailed introduction. Take a look. Bar! How to switch language in Microsoft Teams Answer: Select the specific process in Settings-General-Language: 1. First, click the three dots next to the avatar to enter the settings. 2. Then click on the general options inside. 3. Then click on the language and scroll down to see more languages. 4. Finally, click Save and Restart.

Huawei's self-developed Cangjie programming language official website and development documents are online, integrating into the Hongmeng ecosystem for the first time Huawei's self-developed Cangjie programming language official website and development documents are online, integrating into the Hongmeng ecosystem for the first time Jun 22, 2024 am 03:10 AM

According to news from this site on June 21, before the HDC2024 Huawei Developer Conference, Huawei’s self-developed Cangjie programming language was officially unveiled, and the Cangjie official website is now online. The official website introduction shows that Cangjie programming language is a new generation programming language for all-scenario intelligence, focusing on "native intelligence, natural all-scenarios, high performance, and strong security." Integrate into the Hongmeng ecosystem to provide developers with a good programming experience. The official website attached to this site introduces as follows: Native intelligent programming framework embedded with AgentDSL, organic integration of natural language & programming language; multi-Agent collaboration, simplified symbolic expression, free combination of patterns, supporting the development of various intelligent applications. Innately lightweight and scalable runtime for all scenes, modular layered design, no matter how small the memory is, it can be accommodated; all-scenario domain expansion

What should I do if the Microsoft Edge browser does not display images? - What to do if the Microsoft Edge browser does not display images? What should I do if the Microsoft Edge browser does not display images? - What to do if the Microsoft Edge browser does not display images? Mar 04, 2024 pm 07:43 PM

Recently, many friends have asked the editor what to do if the Microsoft Edge browser does not display images. Next, let us learn how to solve the problem of Microsoft Edge browser not displaying images. I hope it can help everyone. 1. First click on the lower left corner to start, and right-click on "Microsoft Edge Browser", as shown in the figure below. 2. Then select "More" and click "App Settings", as shown in the figure below. 3. Then scroll down to find "Pictures", as shown in the picture below. 4. Finally, turn on the switch below the picture, as shown in the picture below. The above is all the content that the editor brings to you on what to do if the Microsoft Edge browser does not display pictures. I hope it can be helpful to you.

Comparison of the advantages and disadvantages of C++ technology and other modern programming languages Comparison of the advantages and disadvantages of C++ technology and other modern programming languages Jun 01, 2024 pm 10:15 PM

A comparison of the advantages and disadvantages of C++ with other modern programming languages ​​is: C++ advantages: high performance, low-level control, rich library ecosystem. C++ disadvantages: steep learning curve, manual memory management, limited portability. Python advantages: smooth learning curve, extensive library support, interpreted language. Advantages of Java: platform independent, automatic memory management, wide application. Advantages of JavaScript: essential for front-end development, lightweight, dynamic type.