In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about what a multi-paradigm programming language is. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Multi-paradigm programming languages are: (1) object-oriented programming to improve software reusability, flexibility and expansibility; (2) functional programming, with mathematical functions as the core programming paradigm of programming language modeling; (3) generic programming, provides a higher level of abstraction.
Multi-paradigm programming languages include:
Summary:
This paper mainly describes the concepts of three programming paradigms-object-oriented programming, functional programming and generic programming.
Programming paradigm
Programming paradigm is the idea behind programming language. Represents the view of programmers on how programs should be built and executed. Common programming paradigms are: procedural, object-oriented, functional, generic programming and so on.
Some programming languages are specifically designed for a particular paradigm, such as C is a procedural programming language; Smalltalk and Java are pure object-oriented programming languages; and Haskell is a purely functional programming language. Other programming languages do not correspond to programming paradigms one by one, such as Python,Scala,Groovy, which supports object-oriented and functional programming to some extent. C++ is a successful example of multi-paradigm programming languages. C++ supports the same procedural programming paradigm as C language, but also supports the object-oriented programming paradigm. STL (Standard Template Library) makes C++ have the ability of generic programming. Supporting multiple paradigms may be one of the reasons why C++ still has strong vitality until now.
Swift is a typical multi-paradigm programming language, which supports both object-oriented programming paradigm, functional programming paradigm and generic programming. The fact that Swift supports multiple programming paradigms is determined by its creative goals. The original intention of Swift is to provide a practical industrial language. It is different from Haskell, which is an academic programming language from universities and research institutions. Apple launched Swift with a clear business purpose: Mac OS and Objective-C, the main programming language for iOS systems, have grown old, and Swift will enable Apple system developers to have a more modern programming language, thus promoting the healthy development of Apple's entire ecosystem.
The design and development of Swift embodies the goal of "practical industrial language". This determines that Swift is unable to do extreme language experiments, and it needs to seek breakthroughs cautiously on the basis of facing reality rationally. This determines that Swift needs to inherit the historical heritage, take care of the practical needs of most programmers today, and develop for the future.
1. Object-oriented-inheritance
Object-oriented programming takes the object as the basic unit of the program and encapsulates the program and data in order to improve the reusability, flexibility and expansibility of the software.
The core concepts of object-oriented programming:
Polymorphism refers to different classes related to inheritance, whose objects respond differently to the same message.
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 method, and instead sends messages to it through a message passing mechanism.
In the object-oriented programming language that builds the basic unit of a program with objects. Polymorphism provides higher abstraction capabilities, allowing us to design more general-purpose programs. Inheritance provides a way to reuse code. Encapsulation provides a more convenient and secure mechanism for using other code.
Nowadays, the working language of most programmers is still object-oriented programming language. Most popular modern programming languages allow you to create objects. Using object-oriented programming language, it is easy to build software model. Because, objects are very similar and seem easy to do with all things and concepts in the real world. But programming practice shows that not everything is a good thing to be an object. Take a poor example in Java: only objects in Java can be passed into functions as arguments (and of course the original type primitive type). So in order to pass the function to another function, you need to wrap the function in an object, usually using an anonymous class, because this class does nothing else, just to make everything in Java happy for the design of the object.
Java has a pure object-oriented concept. From the beginning of its design, it wants to model the world with a pure object model in which everything is an object. But up to now, more and more non-object things have been added to Java. Closures are introduced to obtain first-order functions in functional programming, and generics are introduced to obtain parameterized types. This may imply that the world is so colorful that modeling the world with a single pattern will not be successful.
2. Functional programming-Development
Functional programming is a programming paradigm that takes mathematical functions as the core of programming language modeling. It treats computer operations as mathematical functions and avoids the use of program states and mutable objects.
There are two main ideas of functional programming:
Taking function as the core of programming language modeling
Avoid state and variability.
Function is the cornerstone of functional programming. The code of a functional programming language is made up of functions. The process of writing a functional language is to design functions. Large-scale programs are made up of thousands of functions, in order to combine these functions effectively. Functional programming languages try to avoid states and mutable objects. The absence of a variable state makes a function in a functional language pure. Pure functions are easier to modularize, easier to understand, and friendly to reuse.
Functional programming languages also produce some useful programming tools:
First-order function, closure
Corialization function
Lazy evaluation.
All of this will be mentioned in later chapters. These programming tools are also increasingly appearing in other programming languages.
Functional programming languages are not young, and their 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 until recently, the idea of functional programming has been paid more and more attention. Almost all newly invented programming languages are more or less influenced by the idea of functional programming. Python,Scala,Groovy,Swift has first-order functions, closures. This allows you to pass the function directly to another function, and the function can be returned by another function in the form of a return value. The benefits of eliminating state and providing immutability are increasingly accepted, and Scala,Groovy,Swift provides a convenient way to declare immutable objects to enable you to write code that is more functional.
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 affecting the development of other programming languages. In the future, it may be difficult for a programming language designed mainly in the functional programming paradigm to become a mainstream programming language. There should be few opportunities for Java to be built in a single programming paradigm (object-oriented) and become a mainstream programming language. The pursuit of a purely functional programming language like Haskell is more likely to be a partial academic language experiment.
To repeat the reasons mentioned in the previous section, the world is so colorful that modeling the world with a single pattern will not succeed.
Object-oriented and functional programming
If we classify the popular languages according to the language paradigm. Supporting object-oriented programming languages should be the longest queue. Most popular modern programming languages are face objects, and they allow you to create objects. But at the same time, you will find that several popular programming languages, Python,Scala, and even Java, are more or less affected by functional programming languages. They all introduce some concepts of functional programming, so that you can write functional-style code to some extent.
After being familiar with the class object-oriented programming language, when you come into contact with the functional programming language, you will often feel refreshed, and even vaguely feel that the functional language is a good way to save the world. So should we turn completely to functional programming languages? Use Haskell to save the world.
After the 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 multithreaded environment; inheritance is not a good way to reuse code). Functional languages do have many advantages, some of which can solve the problem of object-oriented language (pure functions are very suitable for multithreaded environment, pure functions are inherently modular and friendly to code reuse). However, functional programming may also have some problems. These problems may be exposed only after the practice of the industry on a larger scale. We can now be convinced that it is difficult to model the world based solely on objects. Then modeling the world with mathematical models may not be much better. To be sure, they all have areas and environments that they are good at. We still can't use some programming paradigm to solve all the problems.
The bigger reality is that countless enterprises have made huge investments in object-oriented programming languages, even though some problems have been exposed in object-oriented programming, and functional programming shows many advantages that can solve these problems. No one who is cautious will and can not immediately abandon object-oriented programming and turn to functional programming language completely and completely.
The realistic choice is to provide functional support while supporting object-oriented programming. In this way, in most places where object-oriented is easy, you can still use object-oriented methods. Where functional programming is suitable, and you have the thinking and ability of functional programming, you can still improve productivity by functional programming.
3. Generic programming-beautiful embellishment
Generic programming is another interesting topic. Generics provide a higher level of abstraction for programming languages, that is, parameterized types. In other words, it abstracts the type information from an algorithm or class that is originally specific to a certain type. This abstract concept in C++ 's STL (Standard Template Library) is Template. STL demonstrated the power of generic programming and became a powerful weapon for C++ as soon as it appeared. In addition to C++, programming languages such as Clipper, Java, and Haskell have introduced the concept of generics.
Generic programming is a slightly more local concept that only involves how to deal with types more abstractly, that is, parameterized types. This is not enough to support the core concept of a language. We will not hear that a programming language is pure generic programming without other programming paradigms. But just because generics do not change the core of the programming language, most of the time, it can be well integrated into other programming methods. Generics are supported by programming languages that are very different in style, such as Caterpillar, Scala, and Haskell. Generic programming provides a higher level of abstraction, which means greater expressiveness. This is a delicious meal and wine for most programming languages.
Generics are widely used in Swift, and many Swift standard libraries are built from generic code. For example, the array and dictionary types of Swift are generic sets. Such examples can be found everywhere in Swift.
Summary
In this series of articles, we will mainly take Swift as an example to explain the multi-paradigm programming language. The series is divided into three parts to discuss the three programming paradigms supported by Swift:
Object-oriented programming paradigm
Functional programming paradigm
Generic programming
Thank you for reading! This is the end of this article on "what is a multi-paradigm programming language?". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.