elixir开发的项目
by Nikolas O'Donnell
由Nikolas O'Donnell
我对Elixir的介绍:学习另一种编程语言如何使您成为更好的开发人员 (My intro to Elixir: how learning another programming language can make you a better developer)
I attended ElixirConf EU in Warsaw earlier this year. It was actually my first ever programming conference. My colleague was giving a talk about Elixir and Phoenix called ‘Phoenix and the World of Tomorrow’.
我今年早些时候在华沙参加了ElixirConf EU。 实际上,这是我第一次参加编程会议。 我的同事正在谈论有关Elixir和Phoenix的话题,称为“凤凰与明天世界”。
Now, my background is in JavaScript but my company is Elixir obsessed. Having taken a sip of the company kool-aid and seen what it can do — I’m pretty well converted.
现在,我的背景是JavaScript,但我的公司着迷于Elixir。 k了一口公司的kool-aid,看看它能做些什么-我的转换真不错。
JavaScript will always be my first language, and holds a special place in my heart. I’m still using, learning and very much part of the vibrant and growing JavaScript and React community.
JavaScript将永远是我的第一语言,并且在我心中占有特殊的位置。 我仍在使用,学习和学习充满活力且不断发展JavaScript和React社区的大部分内容。
Although I’ve been familiarizing myself with Elixir for work, I have come to see a great deal of value in learning another programming language.
尽管我一直很熟悉Elixir的工作原理,但是我发现在学习另一种编程语言方面具有很大的价值。
It’s a similar experience with learning a new spoken language. You’re pushed outside of your comfort zone. Having to understand and reason in another way, even from another perspective.
学习新的口语也有类似的经历。 您被推到舒适区之外。 即使从另一个角度来看,也必须以另一种方式理解和推理。
Further, you often have to rebuild from first principles — which in turn can have the added benefits of breaking preconceived assumptions and limitations.
此外,您通常必须从第一条原则进行重建,而第一条原则反过来又可以带来打破预先设定的假设和局限性的额外好处。
This is a healthy thing to do and ultimately we should be language, library, and framework agnostic.
这是一件健康的事情,最终我们应该与语言,库和框架无关。
Our job is not actually to write code, and certainly not to write a specific ‘language’ of code.
我们的工作实际上不是编写代码,当然也不是编写特定的“语言”代码。
Rather, it is to solve problems for our companies, clients, and customers.
而是要为我们的公司,客户和客户解决问题。
Having other languages, frameworks and coding paradigms at your disposal when solving a problem increases your chances of solving it in a better way. In addition, it makes you a more well-rounded programmer and valuable team member.
解决问题时使用其他语言,框架和编码范例可以更好地解决问题。 此外,它使您成为更全面的程序员和有价值的团队成员。
进一步探索Elixir (Exploring Elixir further)
Elixir is a relatively new meta-programming language created by Jose Valim and launched in 2012.
Elixir是由Jose Valim创建并于2012年推出的相对较新的元编程语言。
The ‘meta’ part is not just me trying to be ‘hip’, ‘happening’ and ‘down with the cool kids’. It gives an extra piece of information to what Elixir is.
“元”部分不仅是我试图成为“臀部”,“正在发生”和“与冷静的孩子在一起”。 它为Elixir提供了额外的信息。
To explain more about Elixir, I guess I have to first talk a little bit about Erlang. This is because Elixir is built on top of Erlang (hence the “meta” part). It runs on the Erlang virtual machine, called the BEAM because of some acronym that I’d have to DuckDuckGo to find out.
为了解释有关Elixir的更多信息,我想我必须先谈一点Erlang。 这是因为Elixir构建在Erlang之上(因此称为“元”部分)。 它运行在Erlang虚拟机(称为BEAM)上,因为我不得不在DuckDuckGo中找到一些缩写。
Erlang was created by Joe Armstrong, Robert Virding, and Mike Williams, while they were working for Ericsson in the mid 1980’s.
Erlang是由Joe Armstrong,Robert Virding和Mike Williams在1980年代中期为爱立信工作时创建的。
Ericsson works within the telecommunications space. They had the problem of making software that was robust, fault tolerant, and asynchronous — so calls didn’t drop out!
爱立信在电信领域工作。 他们遇到的问题是,开发出强大,容错和异步的软件-因此通话不会中断!
Charged with this mission, these engineers created Erlang. The Danish engineer Agner Krarup Erlang is often cited as the namesake… though it’s also a pretty convenient choice for an Ericsson Language (I’m on to you ಠ_ಠ).
这些工程师担负了这一使命,创建了Erlang。 丹麦工程师Agner Krarup Erlang 经常被援引作为同名......虽然它也是尔 icsson 郎 uage一个相当方便的选择(我对你ಠ_ಠ)。
Back to Elixir. Being a functional language, it is super nice to keep things all ordered, organized and readable.
回到Elixir。 作为一种功能语言,将所有内容保持有序,有条理和可读性是一件非常好的事。
This function does that specific task. This module does this set of functions. Neither really need to know what the other is doing. This modular design pattern makes it easier to keep a clean codebase.
此功能完成该特定任务。 此模块执行此功能集。 双方都不真正需要知道对方在做什么。 这种模块化的设计模式使保持干净的代码库变得更加容易。
It is actually considered a multi-paradigm language as it is functional, concurrent, distributed and process-orientated. Cool story — but what does any of that even mean?
它实际上是一种多范式语言,因为它具有功能性,并发性,分布式和面向过程的特点。 很酷的故事-但这到底意味着什么?
Functional programming uses functions (ideally ‘pure functions’ where the inputs and outputs are clearly declared) with no hidden values coming in or out to build the program. The goal is to remove side effects or unintended outputs from the code.
函数式编程使用的函数(理想情况下是“纯函数”,其中明确声明了输入和输出),没有隐藏的值传入或传出以构建程序。 目的是消除代码中的副作用或意外输出。
Concurrency lets a program execute multiple computations at the same time. It doesn’t have to wait for one thing to finish before starting another. This is referred to as ‘blocking’ because the execution of the next item is blocked from running until the previous item is completed.
并发使程序可以同时执行多个计算。 在开始另一件事之前,不必等待一件事情完成。 这被称为“阻止”,因为阻止下一个项目的执行,直到上一个项目完成为止。
Distributed describes how information is exchanged. In distributed systems, problems are broken down into smaller tasks. These are completed through exchanging messages. As these messages can be talking to each other across machines/networks, it is distributed.
分布式描述了如何交换信息。 在分布式系统中,问题被分解为较小的任务。 这些是通过交换消息完成的。 由于这些消息可以在机器/网络之间相互交谈,因此它是分布式的。
Process-orientated also reflects how problems are broken down into smaller tasks or processes and aims to keep separate the data structures from the processes that interact with them. The reason for wanting to do this is that it allows for programmers to be more assured of getting the result they expect.
以流程为导向还反映了如何将问题分解为较小的任务或流程,并旨在将数据结构与与其交互的流程分开。 想要这样做的原因是,它使程序员可以更有把握地获得他们期望的结果。
This is what Elixir code looks like:
这是Elixir代码的样子:
Clean right, and quite readable — take note of the following pattern:
干净利落,而且可读性强-请注意以下模式:
defmodule <Module_name> do
def <something> do
<the things to do>
|> {you can use the pipe operator (|>) to parse..}
|> {the result from a function..}
|> {as the fist argument to the next function..}
|> {creating a 'pipeline' with a final output..}
|> {of the entire cross function calls!}
end
end
但是所有额外的语法在哪里? (But where is all the extra syntax?)
Well, being a new language, it has the fortune gained from hind sight. The language borrows some of the best aspects of other languages. As mentioned, it is built on Erlang and is actually compatible — meaning you can use Erlang syntax in Elixir code.
好吧,作为一种新语言,它的后代获得了巨大的财富。 该语言借鉴了其他语言的一些最佳方面。 如前所述,它基于Erlang构建并且实际上是兼容的,这意味着您可以在Elixir代码中使用Erlang语法。
It also leverages the clean syntax and code structure of Ruby — its creator having come from a Ruby background.
它还利用了Ruby的简洁语法和代码结构-它的创建者来自Ruby背景。
凤凰 (Phoenix)
Phoenix is a web framework built for Elixir by Chris McCord. You can think of this as a way to bootstrap out a project. It is modular (thanks to Elixir). It is also super fast (thanks to Erlang), and ultimately very powerful.
Phoenix是Chris McCord为Elixir构建的Web框架。 您可以将其视为引导项目的一种方式。 它是模块化的(感谢Elixir)。 它也非常快(感谢Erlang),最终非常强大。
You can use it as the API layer between your database and your front end. You can also easily use the HTML and CSS templates that come with Phoenix. You can use Brunch JS to inject these parts into your website/app.
您可以将其用作数据库和前端之间的API层。 您还可以轻松使用Phoenix随附HTML和CSS模板。 您可以使用Brunch JS将这些部分注入您的网站/应用程序。
Alternatively, you could also use a front-end framework like Ember or React to do the same — making it a ‘best of both worlds’ approach.
另外,您也可以使用Ember或React这样的前端框架来做同样的事情-使其成为“两全其美”的方法。
This is the talk my colleague Ley gave at ElixirConf EU that I mentioned earlier. It is well worth a watch, as it looks at the role Phoenix can play in the next billion users accessing the internet on < 3G devices:
这是我前面提到的同事Ley在ElixirConf EU上发表的讲话。 值得一提的是,它着眼于Phoenix在<3G设备上访问互联网的下十亿用户中所扮演的角色:
So if you’re intrigued, why not take a sip of Elixir? I think you might just get hooked.
因此,如果您感兴趣,何不喝一口Elixir? 我想您可能会上瘾。
Though in any case, take a sip of something new. Move out of your programming comfort zone and challenge yourself to explore another language, perspective and way of thinking. What’s the worst that could happen...?
虽然无论如何,还是要喝点新鲜的东西。 离开编程舒适区,挑战自己,探索另一种语言,观点和思维方式。 可能发生的最糟糕的情况是什么?
elixir开发的项目