English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Introduction to Erlang

Erlang is a functional programming language that also has a runtime environment. Its design makes it inherently supportive of concurrency, distribution, and fault tolerance. Erlang was originally developed for use in multiple large-scale telecommunications systems within Ericsson.

The first version of Erlang was developed by Joe Armstrong, Robert Virding, and Mike Williams in1986was developed in the year. It was originally an internal proprietary language of Ericsson. It was later released in1998was released as an open-source language in the year. Erlang, as well as OTP (a collection of middleware and libraries in Erlang), are now supported and maintained by Ericsson's OTP product division and are widely known asErlang/OTP.

Why choose Erlang?

If you have the following requirements, you should use Erlang to develop applications-

  • The application needs to handle a large number of concurrent activities.

  • It should be easy to distribute over computer networks.

  • There should be tools that make the application fault-tolerant to both software and hardware errors.

  • The application should be scalable. This means it should be able to span multiple servers with little change.

  • It should be easy to upgrade and reconfigure without stopping and restarting the application itself.

  • The application should respond to users within a certain strict time frame.

The official website of Erlang ishttps://www.erlang.org/.

Introduction

Erlang is a general-purpose concurrent programming language, developed by the CS division of the Swedish telecommunications equipment manufacturer Ericsson.-Lab development aims to create a programming language and runtime environment that can handle large-scale concurrent activities. Erlang was introduced in1987Year, after ten years of development,}1998Year, the open-source version was released. Erlang is an interpreted language that runs on a virtual machine, but now it also includes a local code compiler developed by the Uppsala University High-Performance Erlang Project (HiPE), starting from R11B-4From the beginning, Erlang also started to support script interpreters. In terms of programming paradigms, Erlang is a multi-paradigm programming language that covers functional, concurrent, and distributed. The sequentially executed Erlang is a functional programming language with early evaluation, single assignment, and dynamic typing.

Erlang is a structured, dynamically typed programming language with built-in support for parallel computing. Initially, it was designed by Ericsson specifically for communication applications, such as control switches or protocol transformations, and is therefore very suitable for building distributed, real-time, and soft real-time parallel computing systems. Applications written in Erlang are typically composed of thousands of lightweight processes that communicate with each other through message passing. Context switching between processes in Erlang is just a few steps, much more efficient than thread switching in C programs.

It is much simpler to write distributed applications using Erlang because its distributed mechanism is transparent: the program itself does not know that it is running in a distributed environment. The Erlang runtime environment is a virtual machine, somewhat similar to the Java virtual machine, so once the code is compiled, it can run anywhere. Its runtime system even allows code to be updated without interruption. Additionally, if higher efficiency is needed, bytecode can also be compiled into native code for execution.

Development History

Erlang was named after the Danish mathematician and statistician Agner Krarup Erlang, and Erlang can also represent Ericsson Language.

Erlang is not a new language; it appeared in1987Year, but at that time, the demand for concurrency and distributed computing was not as widespread as it is today, and it was a time when heroes had no place to display their skills. Joe Armstrong, the founder of the Erlang language, was working on telephone network development at Ericsson at that time. He used Smalltalk, but unfortunately, Smalltalk was too slow to meet the high-performance requirements of telephone networks. However, Joe was really fond of Smalltalk and therefore ordered a Tektronix Smalltalk machine. But it took two months for the machine to arrive, and Joe was bored during the wait and started using Prolog. By the time Tektronix arrived, he was more interested in Prolog. Of course, Joe was not satisfied with just mastering Prolog, so after some experiments, he added concurrency handling and error recovery to Prolog, thus giving birth to Erlang. This is also why the syntax of Erlang has many similarities with Prolog, such as their List expressions being [Head | Tail].

1987That year, the Erlang beta version was released, and it was continuously improved in actual user applications.1991That year, the first version was released to users, with more features such as compilers and graphical interfaces.1992That year, Erlang welcomed more users, such as the RACE project, etc. At the same time, Erlang was ported to various platforms such as VxWorks, PC, and Macintosh, and two product projects using Erlang also began to take off.1993The internal independent organization of Ericsson began to maintain and support the Erlang implementation and Erlang tools.

Language Features

Different from traditional object-oriented languages, it has its own advantages: first, it is based on process concurrency, with lightweight processes that collaborate and handle transactions in an orderly manner. Users do not need to worry about specific PV operations, as these processes are transparent to the operating system, and from the perspective of the operating system, only one process is running. Second, each process has its own independent memory, and inter-process communication relies entirely on message passing. Each process has its own independent mailbox and uses pattern matching to find messages to be processed, then handling them asynchronously. This reduces the coupling between processes and improves their independence. Erlang also has a reliable fault-tolerance mechanism. Since processes are relatively independent, Erlang can use some processes to link or monitor others. When these monitored processes exit abnormally due to errors, the monitoring program will receive messages about their exit and handle them accordingly. In OTP, Erlang can use the monitoring tree to perform one-to-one or one-to-many monitoring. Most importantly, support for multi-core CPUs, in Erlang, the operation of multi-core does not require developers to manage it, and it is completely transparent to developers. We just need to write programs as usual. Finally, Erlang supports hot code upgrades, and code upgrades can be implemented without downtime in Erlang, achieving hot upgrades during software operation. In Erlang's version management, it is possible to retain a module's2Different versions, supporting rollback to previous versions.

Erlang language focuses on certain needs and is not completely suitable for all situations. While it has many attractive features, it also has some drawbacks: its language abstraction ability is not strong, Erlang is a weakly typed language, and it can be relatively convenient to adjust the content of messages or the requirements of patterns when matching. However, when errors occur, these errors are more concealed. Additionally, when the project scale is large, it will be found that due to the characteristics of the language, the parts appear flattened, and there are many tuples and records in the program, resulting in a chaotic program structure. Secondly, functional programming is different from traditional programming languages. Currently, mainstream programming languages are C language-based and object-oriented. Currently, functional programming lacks mature programming theories, and there are fewer talents and resources related to this, which increases the difficulty of learning. Additionally, the object-oriented thought has been deeply rooted in people's minds, making it difficult to change the way of thinking when learning functional programming. Most importantly, Erlang is an IO-intensive language, suitable for projects with obvious distributed characteristics. For calculation-intensive requirements, it may be more difficult, but there is still space for optimization and improvement.

Prospects for development

Erlang has developed rapidly in China in recent years, mainly used for game server system development. Erlang is easy to learn, has a high error tolerance, and is suitable for rapid iteration, which is very suitable for the development of web games and mobile games. Especially in some medium and small game companies in cities like Guangzhou and Shenzhen, almost all of them use Erlang. With c++The game server system based on the basic language requires a long period of technical accumulation, and c++The development efficiency of Erlang is not as good as that of Erlang, and the high recruitment cost is also a huge challenge for emerging companies. However, small and medium-sized companies attach more importance to products than technology, which is not favorable for the development of Erlang in China. Most companies use the same mature Erlang framework, focusing on handling specific business logic while neglecting underlying optimization. This is extremely unfavorable for the development of Erlang.

Erlang has developed for a long time abroad and has been proven to be a mature language. It is currently applied to hundreds of major development projects including Ericsson's broadband, GPRS and ATM switching solutions, etc., with rich project experience. The programming framework (OTP) provides a set of tools and libraries for implementing robustness and fault tolerance for Erlang systems, as well as a complete structured framework. However, compared to domestic game development, it is mainly used in foreign countries for web services, computer telephony, messaging systems, and commercial banks, etc. At the beginning of this century, the Erlang.org website had a total of36000 web pages, ten years later, this number rose to280 thousand, which indicates that the Erlang community is continuously expanding, including business, research and open-source projects, viral marketing, a combination of books and blogs, of course, all of which are derived from the original design of Erlang-The demand for solving specific domain problems and the drive.