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 規格