Learn the strengths of 27 programming languages and improve your Python code level

Time:2022-5-11

Python cat note: Python language has been born for 30 years, and now its development momentum is in full swing, which is largely due to its excellent design that is easy to learn and use. It is undeniable that Python has stolen a lot from other languages. The author of this article is a senior core developer. His broad vision and accurate understanding make me understand Python design more comprehensively. At the same time, his statement of “using pride rather than fear” conveys the principle of “focusing on self-improvement and not jealous of others’ success”, which is also very helpful to me. The original was written in 2015 and has been in my favorites for a long time. Now it has been translated smoothly, which is a meaningful thing to enhance my pride. Finally, I wish you all a good reading.

Author: Nick Coghlan

translator:Pea flower cat @ Python cat

english:https://www.curiousefficiency.org/posts/2015/10/languages-to-improve-your-python.html

Statement: this translation is for the purpose of communication and learning and is based on CC by-nc-sa 4.0 license agreement. The content has been slightly changed for ease of reading.

catalogue

  • Broaden our horizons
  • Procedural programming: C, rust, Python
  • Object oriented data model: Java, c#, Eiffel
  • Object oriented C derivation: C + +, D
  • Array oriented data processing: MATLAB / octave, Julia
  • Statistical analysis: R
  • Computational pipeline modeling: Haskell, Scala, clojure, F#
  • Event driven programming: Javascript, go, Erlang, Elixir
  • Gradient type: typescript
  • Dynamic metaprogramming: hy, ruby
  • Pragmatic problem solving: Lua, PHP, Perl
  • Programming thinking: scratch, logo

As a co designer of one of the world’s most popular programming languages, I often see a frustrating behavior (in the python community and other communities): influential people try to arouse people’s fear of “losing” to other open source communities, so as to mobilize people’s enthusiasm to contribute to the community. (I occasionally make this mistake myself, which makes it easier for me to find out whether others fall into the same trap).

While learning from the experience of other programming language communities is a good thing, a fear based approach to motivating action is seriously problematic because it will stimulate members of the community to see people in other communities as enemies competing for the attention of open source contributors, rather than as potential allies in larger challenges (promoting the art of software Development). It also tells those who like other languages that they are not welcome in a community that sees them and their peers as “hostile competitors”.

In fact, we want to have a variety of cross platform open source programming languages to choose from, because programming languages are the primary tool for thinking – so that we can express our ideas in a clear way so that computers can understand them. If someone finds a language suitable for the brain that can solve the problem at hand, it’s great, no matter what language (s) they choose.

Therefore, I have three specific requests for the python community and a broader suggestion. First of all, my request is:

  1. If we want to use the instinct of the community to stimulate action, we should avoid using fear and use pride.When we use fear as an incentive, it’s like saying “if we don’t do X, we’ll lose developers’ attention to Python”, which is tantamount to deliberately creating pessimism among free open source contributors. However, relying on the pride of the community is like saying, “it’s not clear how to solve the X problem in Python. If we look at the Y language, we can see that they have a very good way to solve the X problem, and we can absorb it into Python to provide a similar comfortable user experience.” A positive attitude makes us proud of our efforts rather than belittle the efforts of others, which helps to promote a culture of continuous learning in the python community and promote the improvement of collaborative relations and common development with other communities.
  2. Refrain from dismissing other open source programming language communities, especially when they empower people to solve their problems rather than waiting for commercial software vendors to solve them.Most of the world’s important problems are unprofitable to solve (because the people who suffer from these problems are not rich and cannot control the decisions of institutional funds), so we should encourage those who try to solve these problems, no matter how we look at their technological choices.
  3. **If people we know are just beginning to learn programming and they choose a language we don’t like, we should support their choice** They know better than us what is suitable for them, and the language suitable for us may not be suitable for them. If they are frustrated with their initial choice and even have no motivation to learn programming, recommend another programming language to them at this time. This suggestion also applies to those who are improving the poor network security situation: when facing the inherently unsafe language, the way we take is to improve the sandbox function of the operating system, gradually learn the language with better local security attributes, and improve the default behavior of the existing language, rather than listing why the language they choose is a bad choice from the perspective of program security to confuse beginners. (if someone deploys unaudited software written by beginners to handle security sensitive tasks, it’s not the developer’s problem, and the deployer’s problem is that they don’t conduct proper due diligence on the provenance and security attributes of the software.)

My broad advice is for those who encounter the limitations of Python’s core programs and therefore want to explore the “thinking tools” available in Python. This suggestion is:

Broaden our horizons

In the process of developing Python core programs, one thing we will do is to look at the features in other languages that solve the problems we are facing, and see if there is a way to absorb them and make Python code easier to read and write. This means that learning other programming languages that focus on a specific software development style can help us improve our understanding of this programming style when using python.

To help, I have listed below some areas worth exploring, as well as languages that may deepen my understanding of these areas. I try to link to the Wikipedia page rather than directly to the language home page, because Wikipedia often provides interesting historical background. When you learn a new programming language for educational purposes rather than directly use it in practical applications, these background values need to be understood.

Although I know most of these languages (and have used several when developing production systems), this recommendation list also includes languages I know indirectly (usually by reading tutorials and design documents, or by talking to people I trust to gain insight into the advantages and disadvantages of a language).

There are many languages that should have been put on the list but not on the listlanguageTherefore, the following list is only the parts I am interested in (for example, I am mainly interested in the ecosystems of Linux, Android and windows, so I abandoned the Objective-C and swift languages in the apple ecosystem, and I am not familiar with themProcessingThis art focused programming language can’t imagine what learning them can teach Python developers).

In addition to considering what a language might teach you, if you want to get a more comprehensive list, you can check IEEE spectrum on the popularity and growth of programming languagesAnnual list

Procedural programming: C, rust, Python

Python’s default execution model is procedural: start from the top of the main module and execute sentence by sentence. Python’s support for all data and programming modeling methods described below is based on this procedural execution model.

C language is still the undisputed ruler of the underlying procedural programming. It is the official interpreter of Python and the core implementation language of the Linux operating system kernel. As a software developer, learning C language is one of the best ways to learn more about the underlying hardware – C language is often called “portable assembly language”. For any new CPU architecture, the first cross compiled application will be c compiler.

RustIs a relatively new programming language created by Mozilla. The goal of rust is to learn all the lessons encountered by the whole industry when not using C, design a new language that can interoperate with C library, and provide precise control over the purpose of hardware required by the underlying system programming, but use different compilation methods for data modeling and memory management, Structurally eliminate many common defects that perplex C programs (such as buffer overflow, pointer repeated release error, null pointer access and thread synchronization). After training and early professional experience, I am an embedded system engineer, and rust is the first new language I have seen that seems to have the potential to reduce the current niche dominated by C language and custom assembly code.

CythonIt is also a low-level procedural language, but unlike general-purpose languages such as C and rust, Python is specially used to write Cpython extension modules. To achieve this goal, Python is designed as a superset of python, allowing programmers to choose when to support pure Python syntax for flexibility and when to support Python syntax extension, so as to generate code equivalent to native C code in terms of speed and memory efficiency.

By learning these languages, you can deepen your insights into memory management, algorithm efficiency, binary interface (ABI) compatibility, software portability, and converting source code into operating system.

Object oriented data model: Java, c#, Eiffel

One of the most important things programming does is to model the real world. The most popular way is to provide native syntax to support object-oriented programming: structurally grouping data and using class methods to operate those data structures.

Python itself is carefully designed to use object-oriented features without writing its own classes first. Not every language adopts this approach – the languages listed in this section believe that learning object-oriented design is a necessary condition for using the language.

In the middle and late 1990s, Sun Microsystems carried out a large-scale market promotion,JavaIt has become the default language for introductory courses of Computer Science in many colleges and universities. Although Java has been replaced by Python in many teaching activities, it is still one of the most popular languages for developing commercial programs. There are also languages based on the common JVM (Java virtual machine) runtime, such as the Jython implementation of Python. The Dalvik and art environment of Android system is the secondary development of open API based on Java.

C#Similar to Java in many ways, c# became an alternative after sun and Microsoft failed to resolve their business differences about Microsoft’s Java implementation (i.e. j + +). Like Java, it is a popular language for developing business programs, and some other languages share it Net CLR (common language runtime), including the ironpython implementation of python (the core components of the earliest ironpython 1.0 are extracted into a language independent. Net dynamic language runtime). For a long time Net is a technology dedicated to windows, andmonoAs a cross platform open source implementation, but Microsoft turned to it in early 2015Open source ecosystem strategy

Unlike most of the languages in this list, I don’t recommend using them in daily workEiffel。 However, I still recommend learning it because it has taught me a lot about good object-oriented design. For example, it believes that “verifiable correctness” is the design goal of applications. (learning Eiffel also makes me understand why “verifiable correctness” is not the design goal of most software development, because verifiable correct software can’t deal with fuzziness well, and it’s not applicable to those situations where you don’t know the relevant constraints but need to leave enough room for maneuver so that you can find more specific details through iterative development.)

By learning these languages, you can have an in-depth understanding of inheritance model, contractual design, class invariance, preconditions, postconditions, covariance, inversion, class method parsing order, generic programming and other concepts applicable to Python type system. Many standard library modules and third-party frameworks use this “visible object-oriented” design style, such as unittest and logging modules, as well as class based views in Django framework.

Object oriented C derivation: C + +, D

Cpython running environment can be regarded as a “C with objects” programming environment – at its core, Cpython uses the C method to realize object-oriented programming, that is, define the C structure to save relevant data, pass the instance of the structure to the function as the first parameter, and then operate on the data (this is the omnipotent pyobject * pointer in Cpython C API). This design pattern corresponds to the python level, which is the explicit self parameter of the instance method and the explicit CLS parameter of the class method.

C++The goal is to maintain full compatibility with C language source code while adding more advanced features, such as support for native object-oriented programming and template based metaprogramming. It is notoriously verbose and difficult to program (although the update of language standards in 2011 solved many bad problems), it is also the first choice for programming in many fields, including the graphical engine of 3D modeling and the development framework of cross platform applications (such as QT).

DThe language is also interesting because its relationship with C + + is similar to that between rust and C: its goal is to retain most of the satisfactory features of C + + while avoiding many of its problems (such as lack of memory security). Unlike rust, D is not a new programming language designed from scratch – on the contrary, D is a derivative of C + +. Although it is not a strict C superset like C + +, it follows a design principle that any code falling into the common subset of C and D must be consistent in the two languages.

By learning these languages, you can gain a deeper understanding of the complexity of combining the characteristics of high-level languages with the underlying C runtime model. Learning C + + and operating libraries and toolkits written in C + + in Python may also be helpful.

Array oriented data processing: MATLAB / octave, Julia

Array oriented programming is to support numerical programming models: those based on matrix algebra and related numerical methods.

Although Python’s standard library does not directly support this, python has considered array oriented programming in its design and is specially designed for third partiesNumPyLibraries and similar array oriented tools add a series of syntactic and semantic features.

In many ways, Python’sScience and technology stackAs a businessMATLABThe latter is widely used in modeling, simulation and data analysis in the fields of science and engineering.GNU OctaveIs an open source program, the goal is compatible with the syntax of matlab code, allowing people to compare these two array oriented programming methods.

JuliaIs another relatively new language, focusing on array oriented programming and type based function overloading.

By learning these languages, you can understand Python’s science and technology stack and have the opportunity to explore parallel execution at the hardware level through technologies such as OpenCL and NVIDIA’s CUDAApache SparkAnd python specificBlazeTo understand distributed data processing.

Statistical analysis: R

With the increasing exposure to large data sets, there is an increasing demand for analysis tools that can flexibly deal with these data sets. R programming language is such a tool, which pays special attention to statistical data analysis and visualization.

Learning r will give you an in-depth understanding of Python’s statistical analysis ability in the science and technology stack, especiallypandasData processing library andseabornStatistical visualization library.

Computational pipeline modeling: Haskell, Scala, clojure, F#

Object oriented data modeling and array oriented data processing mainly focus on static data, whether in the form of named attributes or structured data.

In contrast, functional programming language emphasizes modeling dynamic data in the form of computational flow. Even learning the basic knowledge of functional programming can greatly improve the structure of data conversion operation, even in other procedural, object-oriented or array oriented programs.

HaskellIs a functional programming language, which has a significant impact on the design of Python. The most significant is the list derivation introduced in Python 2.0.

ScalaIs a (questionable) JVM functional programming language, plus Java, Python and R, which are the four main programming languages of the Apache spark data analysis platform. Although Scala’s design focuses on functional programming, its syntax, data model and execution model are also designed to minimize the threshold for Java programmers to use (so it is called “questionable” – actually because Scala is best classified as an object-oriented programming language with strong functional programming support).

ClojureIs another JVM based functional programming languageLispA dialect of. It appears in this list because it is the inspiration for Python’s toolz functional programming toolkit.

F#It’s not a language that I’m particularly familiar with, but it’s as Net CLR (common language runtime) recommended functional programming language, so it is still worthy of attention.

By learning these languages, you can have an in-depth understanding of Python’s own computational pipeline modeling tools, including container derivationgenerator Generator, expression, functools and itertools standard libraries, and third-party Python function toolkits, such as toolz.

Event driven programming: Javascript, go, Erlang, Elixir

Computing pipeline is an excellent way to deal with data transformation and analysis problems, but many problems require programs to run as persistent services, wait for events to occur, and then deal with those events. In this kind of service, in order to accommodate multiple users (or multiple operations) at the same time, multiple events must be processed concurrently.

JavaScriptOriginally developed as an event processing language for web browsers, it allows web developers to respond locally to client operations (such as mouse clicks and key taps) and events (such as the rendering of web pages). All modern browsers support it. Together with the HTML5 domain object model (DOM), it has become a de facto standard for defining the appearance and behavior of user interfaces.

GoIt is a special language designed by Google to create highly scalable web services, and has proved to be a very suitable language for developing command-line applications. From the perspective of programming language design, the most interesting aspect of go is the use of communication sequential processes in its core concurrency model(Communicating Sequential Processes)Concept.

ErlangIs a proprietary language designed by Ericsson to create highly reliable telephone exchanges and similar devices. It is used to develop the popular rabbitmq message broker middleware. Erlang uses the actor model as the core concurrency primitive to pass messages between execution threads instead of letting them share data directly. Although I have never used Erlang for programming, my first full-time job involved a C + + concurrency framework based on actor, which was developed by a former Ericsson engineer. In addition, I also developed such a framework based on TSK (task) and MBX (mailbox) primitives in Texas Instrument’s lightweight DSP / BIOS runtime (now ti-rtos).

ElixirIt appears in this list because it is designed to run on Erlang VM and provides the same concurrency semantics as Erlang. At the same time, it also provides a series of language level features to create a more comprehensive environment and is more likely to attract developers of other languages such as python, Java or ruby.

By learning these languages, you can have an in-depth understanding of Python’s support for concurrency and parallelism, includingPrimary synergy, CO process based on generator, concurrent Futures and asyncio standard library module, third-party network service development framework (such as twisted and tornado), channel concept introduced in Django, event processing loop in GUI framework.Python advanced

Gradient type: typescript

A controversial feature in Python 3.5 is the newly introduced typing module, which brings a standard dictionary supporting gradient types to the python ecosystem.

Python cat note: granular typing is a theory proposed by Jeremy siek and Walid Taha in 2006, which allows both dynamic and static types to appear in programs. Some people in China translate it into “progressive type”, “progressive type”, “progressive finalization”, “dynamic and static mixed type”, etc., but I think it is not good enough.gradient type Perhaps it is my initiative to use the gradient color from Photoshop to express the characteristics of transition (or blending and coexistence) from dynamic type to static type. The term “gradient” means to break the state of clear boundaries (such as size, distance, light and shade), so as to achieve the state of neutralization.

For those who come into contact with static types mainly from languages such as C, C + + and Java, this seems to be a surprisingly bad feature (and therefore controversial).

MicrosoftTypeScriptProvides a gradient type for JavaScript programs, so it can better explain this concept. Typescript code will be compiled into JavaScript code (and then run-time type checking will not be included), and typescript annotations of popular JavaScript libraries will be maintained in dedicated librariesDefinitelyTypedCangzhong.

Just as Chris Neugebauer wasPycon speech in AustraliaAs pointed out in, this is much like Python andtypeshedThe relationship between type hint libraries and type inference and analysis tools like mypy.

In essence, type hints in typescript and python are ways to write specific kinds of tests, either using separate files (like normal tests) or embedded in the body of the code (like type declarations in static type languages). In both cases, you need to run a separate command to check whether the rest of the code is consistent with the added type assertion (for typescript, this happens implicitly when compiling into JavaScript; for Python type prompt, this is a completely optional static analysis task).

Dynamic metaprogramming: hy, ruby

C. When learners of languages such as C + +, c# and Java come into contact with Python, a feature they often feel uneasy about is “code is data”: things such as functions and classes are runtime objects that can be manipulated like other objects.

HyIs a lisp dialect that can run on both Cpython VM and pypy VM. LISP and its dialect push the concept of “code is data” to the extreme, because LISP code consists of nested lists that describe the operation to be performed (the name of the language itself represents the list processor). The strength of LISP style language is that it makes it very easy for you to write your own domain specific code. The biggest disadvantage of LISP style language is that it makes it very easy for you to write your own domain specific code, but it may make the code written by everyone difficult to read.

RubyThe language is similar to Python in many ways, but the ruby community is relatively open to Python’s “support but not encourage” dynamic metaprogramming features. This includes adding new methods to existing class definitions and using closures to implement the core structure of the language, such as iterations. (Python cat note: for the implementation comparison of iterative structure in the two languages, you can readThis article

Learning these languages can give you an in-depth understanding of Python’s own dynamic metaprogramming features, includingFunction and class decorators, monkey patch, unittest Mock standard library and third-party object proxy modules such as wrapt. (I don’t know which language I can learn to have an in-depth understanding of Python’s metaclass system. If anyone has any suggestions in this regard, please let me know in the comments. Python’s metaclasses drive many features, such as the core type system, abstract base classes, enumeration types and runtime evaluation of gradient type expressions.)

Pragmatic problem solving: Lua, PHP, Perl

Mainstream programming languages do not exist in isolation – they exist as part of a larger ecosystem of publishers (businesses and community organizations), end users, framework developers, tool developers, educators, and so on.

LuaIs a popular programming language, which is embedded into large programs as a script engine. The iconic example is that it is used by world of Warcraft games to write client-side plug-ins, and it is also embedded in the RPM components used by many Linux distributions. Compared with Cpython, Lua’s runtime is usually only one tenth the size of Cpython, and due to its weak introspection ability, it is easier to isolate from other parts of the program and the server’s operating system. A significant contribution of lua community to Python ecology is luajit FFI (foreign function interface), which is adopted by Cpython and pypy as the basis of cffi interface library supporting JIT.

PHPIs another popular programming language, rising as “P” in the Linux Apache MySQL PHP lamp technology stack, because it focuses on generating HTML pages and is widely used in early virtual private server (VPS) providers. Despite its desperate conceptual flaws in design, it is now the foundation of several extremely popular open source web services, including Drupal content management system, wordpress blog engine and Wikipedia’s MediaWiki engine. PHP also supports some important services, such asUshahidiPlatform, which is an open source social news release community.

Like PHP,PerlIt is also based on Linux. But unlike PHP as a web development platform, Perl is a tool for system administrators. In the text-based Linux operating system, it uses regular expressions to convert the output of commands into strings and operate them. Perl comes in handy when sh, awk, and sed are not competent for certain tasks.

Learning these languages is unlikely to obtain any beautiful aesthetic or elegant concepts in programming language design. The most likely way to learn them is to understand how the programming language is distributed and adopted in reality, and to what extent these depend on accidental opportunities, historical accidents, and the publisher’s default integration in the system, which reduces the use threshold, rather than on the inherent ability of the language itself.Python advanced

In particular, it can provide insight into the importance of ckan, openstack nfv, blender, SciPy, openmdao, pygmo, pycuda, raspberry foundation and python, which are adopted by a large number of business organizations to protect their continuous investment in the python ecosystem.

I often talk to proponents of functional programming and object-oriented programming, who claim that such languages are as easy to learn as procedural languages.

If we are talking about teaching through embedded programming (such as robots), and the objects modeled in the software have real-world counterparts, such as sensors, motors and relays that students can touch, then I think OOP people have a certain reason.

But for others, I now have a standard challenge: pick up a cookbook, translate one of the recipes into a programming language you think is easy to learn, and then find a student who can understand the language in the cookbook and let him operate according to the translated recipes. In fact, they don’t need to really operate – just do an ideological experiment to realize how much a priori knowledge they claim to be “easy to learn” is assumed. (I’m looking forward to seeing academic researchers do this kind of research in reality – I really want to see the results)

Another way to solve this problem is to learn languages that are actually used to teach children programming thinking.

One of the most popular isScratch, it uses a drag and drop programming interface, which allows students to manipulate an independent graphics environment. The electronic graphics in it can move and respond to events in the environment. A graphic environment like scratch is equivalent to a picture book we use to teach children to read and write.

The idea of using a special educational language to operate a graphical environment is not new. One of the earliest examples was invented in the 1960sLogoenvironment In the logo (and similar environments, such as Python’s turtle module), you mainly deal with a “turtle”. You can draw lines to guide it to move and modify the environment. In this way, command sequences, repetitions, and states (e.g. “start”, “end”) can be used based on people’s natural intuition (“imagine you’re the tortoise, what happens if you turn 90 degrees right?”)

Reviewing and relearning these languages will help experienced programmers put aside fixed concepts: the concepts they use can remind us that these concepts are taken for granted today, but beginners need to learn them first. When doing so, we can get along better with students and other beginners, because we are more likely to open the shackles of logic and will no longer ignore the necessary learning steps.

Translator’s note: the above is all the translations. I have also translated many high-quality articles and share some recent articles as follows:

1、Through the for loop, compare the differences between Python and Ruby Programming ideas

2、Python official Seminar: is it really feasible to completely remove Gil?

3、Chat with the father of Python: faster Python!

4、Go deep into the Python interpreter source code, and I finally understand the principle of string persistence!

5、Why doesn’t Python have function overloading? How to realize function overloading with decorator?

6、Python optimization mechanism: constant folding

If you think this article is helpful, please like + pay attention to and support it. Thank you!