elixir 规格_Elixir:一种高画质的编程语言

elixir 规格

by CityBase

按CityBase

Elixir:一种高画质的编程语言 (Elixir: A Big-Picture Programming Language)

Elixir使程序员的工作更好,并且使他们的工作更好 (Elixir makes programmers better at their work, and it makes their work better)

About a year ago, I decided to pursue the chance to work with Elixir full time as lead engineer at CityBase. Since I began using the programming language in 2014, my goal has been to use, grow, and learn more from Elixir.

大约一年前,我决定寻求机会与Elixir一起在CityBase担任首席工程师。 自2014年开始使用编程语言以来,我的目标一直是使用,发展和学习Elixir。

CityBase attracted me for other reasons, too. I’ve always been curious about making complex systems work better. With government technology, we have the challenge to make some of the most complex systems work more effectively for people on a massive scale, to massive impact.

CityBase也因其他原因吸引了我。 我一直对使复杂系统更好地工作感到好奇。 借助政府技术,我们面临着使一些最复杂的系统更有效地工作的挑战,从而使大规模的人们受益。

These objectives — growing Elixir and coding for large-scale impact — are in my opinion the same. I really believe that today, reliability, concurrency, and fault tolerance are foundational qualities that most applications should be built on. Elixir can help with that based on a battle-proven list of applications and concepts.

在我看来,这些目标-增长Elixir和编写具有广泛影响力的代码-是相同的。 我真的相信,今天,可靠性,并发性和容错能力是大多数应用程序应建立的基础素质。 Elixir可以根据经过实践验证的应用程序和概念列表为您提供帮助。

一种经过考验的新语言 (A New Language with Tested Roots)

Elixir is a new language created in 2011. It’s built with the principles of Erlang, a system developed in 1986 for the telecom industry. Erlang is the reason your phone is never temporarily shut down for maintenance. It’s responsible for hardware flexibility and scalability, so you can replace a phone and have your account work the same, and add new phone lines without affecting performance.

Elixir是2011年创建的一种新语言。它是根据1986年为电信行业开发的系统Erlang的原则构建的。 Erlang是您的手机永远不会出于维护目的而永久关闭的原因。 它负责硬件的灵活性和可伸缩性,因此您可以更换电话并让您的帐户保持不变,并添加新的电话线而不会影响性能。

Even though Elixir is relatively young, it relies on Erlang’s proven virtual machine (VM), called BEAM, and its principles of high availability, adaptability, and scalability. These features are exceptionally important in govtech applications, where the fundamental services delivered by technology must be available to everyone.

尽管Elixir相对较年轻,但它依赖于Erlang久经考验的虚拟机(VM)(称为BEAM)及其高可用性,适应性和可伸缩性的原理。 这些功能在govtech应用程序中尤为重要,在该应用程序中,技术交付的基本服务必须对所有人都可用。

程序员的编程语言 (The Programmer’s Programing Language)

Engineers like me are excited to work with Elixir because it helps us be better at our jobs. To code with Elixir, developers need to be in tune with overall business objectives, and code with the future flexibility in mind.

像我这样的工程师很高兴与Elixir合作,因为它可以帮助我们更好地开展工作。 要使用Elixir进行编码,开发人员需要与总体业务目标保持一致,并在考虑未来灵活性的情况下进行编码。

It includes tools that encourage programmers to plan around what can go wrong, and focus on getting as close as possible to the ideal outcome for the end user.

它包含一些工具,这些工具可以鼓励程序员围绕可能出现的问题进行计划,并专注于尽可能接近最终用户的理想结果。

Having programmers who understand the desired big-picture outcomes can be a game changer.

让程序员了解所需的总体效果可以改变游戏规则。

If you ask someone to write code that performs a certain function, they’ll write that code. But if you ask them to write code that leads to an experience or solves a problem, they may think of a solution you never considered — and foresee problems you didn’t know existed.

如果您要求某人编写执行特定功能的代码,那么他们将编写该代码。 但是,如果您要求他们编写可带来经验或解决问题的代码,则他们可能会想到您从未考虑过的解决方案-并预见到您不知道存在的问题。

Elixir encourages this kind of big-picture thinking in its DNA. A shared characteristic of Elixir and Erlang is that they are holistic programming languages. You could easily use Elixir to develop just one service, but it is optimized for developing large systems of many services.

Elixir在其DNA中鼓励这种大图思维。 Elixir和Erlang的共同特点是它们是整体编程语言。 您可以轻松地使用Elixir仅开发一项服务,但是它已针对开发包含许多服务的大型系统进行了优化。

容错的语言 (A Language That’s Fault-Tolerant)

Like death and taxes, another certainty in life is that things will go wrong.

像死亡和税收一样,生活中的另一个确定性是事情会出错。

Elixir has native fault tolerance for the two major types of programming errors.

Elixir具有两种主要类型的编程错误的本机容错能力。

错误类型1 (Error Type 1)

The rarest issues are usually discovered in production and are by definition harder to test for. For instance, connectivity (when a service goes down or is taking longer than expected) between a third-party service or a system resource, such as a database.

最稀有的问题通常在生产中发现,并且根据定义很难进行测试。 例如,第三方服务或系统资源(例如数据库)之间的连接(当服务中断或花费比预期更长的时间)。

To be fault-tolerant to these issues, your system must always be available to customers by using at least two servers. This is to address hardware issues, network problems, or other errors that live outside your program.

为了容忍这些问题,您的系统必须始终通过至少使用两台服务器供客户使用。 这是为了解决程序外部的硬件问题,网络问题或其他错误。

Elixir runs on Erlang’s BEAM VM, which is configured as a mini OS on top of the server OS. The VM is responsible for the communication between servers and nodes. A node will be notified when another node is down, and the system will act in response.

Elixir在Erlang的BEAM VM上运行,该BEAM VM被配置为服务器OS之上的迷你OS。 VM负责服务器和节点之间的通信。 当另一个节点关闭时,将通知该节点,系统将作为响应进行操作。

错误类型2 (Error Type 2)

Issues associated with data are easier to test and can be reproduced locally. For example, if a function that does any math calculation receives a string instead of a number, that function will fail.

与数据相关的问题更易于测试,可以在本地复制。 例如,如果执行任何数学计算的函数收到的是字符串而不是数字,则该函数将失败。

For a program to be fault-tolerant here, your system must be able to “heal” itself during errors stemming from logic bugs, wrong input data, and other internal failures.

为了使程序在这里具有容错性,您的系统必须能够在由于逻辑错误,错误的输入数据和其他内部故障而引起的错误中“自我修复”。

As Elixir is a compiled language, any mistakes in the code prevent the application from starting. This ensures that running applications at least have a valid starting state.

由于Elixir是一种编译语言,因此代码中的任何错误都会阻止应用程序启动。 这样可以确保正在运行的应用程序至少具有有效的启动状态。

For this to work smoothly, the Erlang VM uses something called the supervision principle, which goes like this:

为了使此操作顺利进行,Erlang VM使用了称为“监督原则”的东西,如下所示:

  • Processes are structured based on the idea that there are both “worker” and “supervisor” modules built into a given program.

    流程是基于这样的思想构造的:给定程序既内置了“工人”模块,又内置了“主管”模块。
  • Workers perform computations, and supervisors monitor workers.

    工人进行计算,主管监督工人。
  • If something goes wrong, a supervisor can restart a worker to its initial valid state.

    如果出现问题,主管可以将工作人员重新启动到其初始有效状态。

The supervision principle is associated with process isolation, when one module can run in one isolated process. This ensures that errors in one module will not affect other parts of the application, and you can restart that module in isolation as well.

当一个模块可以在一个隔离的进程中运行时,监督原则与流程隔离相关。 这样可以确保一个模块中的错误不会影响应用程序的其他部分,并且您也可以独立地重新启动该模块。

模块化且可扩展构建的语言 (A Language That’s Modular and Built to Scale)

Elixir is a modular language, meaning that you can modify self-contained parts without worrying about impacting other, unrelated parts. Microservices function concurrently. These code-based actions all play roles in the greater program you’ve created, but tasks are distributed so that they are not dependent on one another to work. This reinforces the benefits of failing fast — you take one faulty player out, and the game still continues.

Elixir是一种模块化语言,这意味着您可以修改独立的零件而不必担心会影响其他不相关的零件。 微服务同时运行。 这些基于代码的动作都在您创建的更大程序中扮演角色,但是任务是分布式的,因此它们彼此不依赖。 这增强了快速失败的好处-您将一名错误的玩家带出,游戏仍然继续。

This also becomes crucial as a codebase grows: in non-modular systems, it’s not always clear when one part impacts others — or which other parts it might impact. This means that even the smallest change requires that you test everything to ensure that the change didn’t break anything. This makes for a daunting amount of work, which means projects move slowly and require lots of people.

随着代码库的增长,这也变得至关重要:在非模块化系统中,并不总是清楚某个部分何时会影响其他部分,或者它可能影响哪些其他部分。 这意味着即使最小的更改也需要您测试所有内容,以确保更改不会破坏任何内容。 这需要艰巨的工作量,这意味着项目进展缓慢,需要很多人。

It also means that training new developers is difficult and time-consuming, as they must familiarize themselves with a complex code legacy in order to effectively expand it.

这也意味着培训新的开发人员既困难又费时,因为他们必须熟悉复杂的代码遗产才能有效地进行扩展。

With Elixir, developers focus on the future, and ensure they’re coding for new or evolving goals, rather than a previous vision that’s baked into overly complex code.

使用Elixir, 开发人员可以着眼于未来,并确保他们正在为新的或不断发展的目标进行编码 ,而不是将先前的愿景植入过于复杂的代码中。

Beyond its modularity, Elixir is also highly scalable. The language enables you to start building an application running only one or two servers and to add more as needed. Together, the servers function as part of a cluster in a distributed system to achieve high availability and scalability.

除了模块化之外,Elixir还具有高度可扩展性。 使用该语言,您可以开始构建仅运行一台或两台服务器的应用程序,并根据需要添加更多服务器。 服务器一起作为分布式系统中群集的一部分,以实现高可用性和可伸缩性。

Within that cluster, servers communicate using an Erlang-based protocol, rather than having to implement or use any application protocol like HTTP, and pick a data serialization/deserialization option like JSON or Protocol Buffers. That means you don’t need to implement anything to pass data between services in different servers/nodes. This is huge in terms of complexity of logic for communication.

在该群集中,服务器使用基于Erlang的协议进行通信,而不必实现或使用任何应用程序协议(例如HTTP),并选择数据序列化/反序列化选项(例如JSON或协议缓冲区)。 这意味着您无需执行任何操作即可在不同服务器/节点中的服务之间传递数据。 就通信逻辑的复杂性而言,这是巨大的。

没有利基的语言 (A Language That Has No Niche)

Obviously, I’m a fan of Elixir. It’s got a lot going for it, from its proven infrastructure to its scalability. But maybe the coolest thing about this language is that it’s industry agnostic. Already, it’s been adopted by a range of companies, for a variety of purposes: WhatsApp, Bleacher Report, Netflix, Pinterest, Postmates, and a handful of .gov sites all use Elixir or Erlang.

显然,我是Elixir的粉丝。 从成熟的基础架构到可扩展性,它有很多工作要做。 但是,也许关于这种语言的最酷的事情是它与行业无关。 它已经被许多公司用于各种目的:WhatsApp,Bleacher Report,Netflix,Pinterest,Postmates和少数.gov网站都使用Elixir或Erlang。

This is a plus for several reasons: first, it means that the language is likely to continue to grow in popularity as companies recognize the benefits it can offer. That, in turn, means that developers will continue to learn it, which means there’s not likely to be a shortage of developers who know Elixir. Companies of all sizes should be able to find developers at all levels to work with Elixir.

这是一个加号,其原因如下:首先,这意味着随着公司认识到它可以提供的好处,该语言可能会继续流行。 反过来,这意味着开发人员将继续学习它,这意味着知道Elixir的开发人员不会很短缺。 各种规模的公司都应该能够找到各个层次的开发人员来与Elixir合作。

Given the power this language has to improve user experience, minimize downtime, and make life easier for dev teams, these are indicators everyone should be cheering — especially those of us in engineering and programming fields.

鉴于该语言具有改善用户体验,最大程度地减少停机时间并简化开发团队生活的功能,这些都是每个人都应该欢呼雀跃的指标,尤其是我们在工程和编程领域的指标。

For those of us in govtech, Elixir is especially promising, as it embodies the kind of resilience and long-term focus essential to making governments function better for everyone.

对于我们中的那些政府官员来说,Elixir尤其具有发展前途,因为它体现了韧性和长期关注点,这对于使政府更好地发挥作用至关重要。

• • •

•••

By Pedro Assumpcao, Lead Software Engineer at CityBase

作者:CityBase的首席软件工程师Pedro Assumpcao

翻译自: https://www.freecodecamp.org/news/elixir-a-big-picture-programming-language-755dcef2fa6a/

elixir 规格

Table of Contents 第⼀部分:基础 Introduction 基础集合Enum 模块 模式匹配 控制语句 函数管道操作符 模块(Module) Mix 魔符(Sigil) ⽂档模块 测试推导字符串 ⽇期和时间 ⾃定义Mix任务 IEx辅助函数 第⼆部分:⾼级 1 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 3.1 3.2 3.3 3.4 4.1 4.2 4.3 和Erlang互操作 错误处理 可执⾏⽂件 并发OTP并发 OTP Supervisors OTP 分布式 元编程 Umbrella Projects Specifications and types ⾏为GenStage 协议Nerves 第三部分:ECTO Basics Changesets 关联关系 查询第四部分:专题 Plug 嵌⼊的 Elixir(EEx) Erlang 项式存储(ETS) 2 4.4 4.5 5.1 5.2 5.3 5.4 5.5 5.6 Mnesia 数据库 调试第五部分:程序库 Guardian(基础) Poolboy Benchee Bypass Distillery(基础) StreamData 3 Introduction 绪⾔第⼀部分:基础 基础集合Enum 模块 模式匹配 控制语句 函数管道操作符 模块(Module) Mix 魔符(Sigil) ⽂档模块 测试推导字符串 ⽇期和时间 ⾃定义Mix任务 IEx辅助函数 第⼆部分:⾼级 和Erlang互操作 错误处理 可执⾏⽂件 并发OTP并发 OTP Supervisors 4 Introduction OTP 分布式 元编程 Umbrella Projects Specifications and types ⾏为GenStage 协议Nerves 第三部分:ECTO Basics Changesets 关联关系 查询 第四部分:专题 Plug 嵌⼊的 Elixir(EEx) Erlang 项式存储(ETS) Mnesia 数据库 调试 第五部分:程序库 Guardian(基础) Poolboy Benchee Bypass Distillery(基础) StreamData
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值