LoginSignup
86
76

More than 5 years have passed since last update.

Elixir の特徴

Last updated at Posted at 2014-10-22

elixir-lang.org のトップページを翻訳しました.
翻訳の誤りなどあればご指摘お待ちしております.


Elixir is a dynamic, functional language designed for building scalable and maintainable applications.

Elixir はスケールしやすくメンテナンスしやすいアプリケーションを作るための動的な関数型言語です.

Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.

Elixir は Erlang VM を活用しています.Erlang VM は低レイテンシで,分散型かつ耐障害性のあるシステムとして知られており,Web 開発や組み込みソフトウェアの領域で使われて成功しています.

To learn more about Elixir, check our getting started guide. Or keep reading to get an overview of the platform, language and tools.

もっと Elixir のことを知るには,getting started guide をご覧ください.あるいはこのまま読み進めるとプラットフォームや言語,ツールについての概要を把握できます.

Platform features -プラットフォームの特徴

Scalabillity - スケールしやすさ

All Elixir code runs inside lightweight threads of execution (called processes) that are isolated and exchange information via messages:

全ての Elixir コードは実行のための軽量スレッド(プロセスと呼ばれています)の中で動きます.軽量スレッドはお互いに分離させられており,メッセージ経由で情報をやりとりします:

parent = self()

# Spawns an Elixir process (not an operating system one!)
# Elixir のプロセス(OS のではないですよ!)を生み出す
spawn_link(fn ->
  send parent, {:msg, "hello world"}
end)

# Block until the message is received
# メッセージを受け取るまでブロックする
receive do
  {:msg, contents} -> IO.puts contents
end

Due do their lightweight nature, it is not uncommon to have hundreds of thousands of processes running concurrently in the same machine. Isolation allows processes to be garbage collected independently, reducing system-wide pauses, and using all machine resources as efficiently as possible (vertical scaling).

軽量な性質により,同じマシン内で数十万のプロセスが同時に動作することも珍しくありません.プロセスは分離しているので,それぞれ独立して GC を受けることができ,システム全体での停止を減らせ,全てのマシンリソースを可能な限り効率的に利用(垂直スケーリング)できます.

Processes are also able to communicate with other processes running on different machines in the same network.This provides the foundation for distribution, allowing developers to coordinate work across multiple nodes (horizontal scaling).

プロセスは同じネットワーク内での異なるマシン上にある別のプロセスとやりとりできます.これは分散の基盤として提供され,開発者は複数のノードに跨がる作業をうまく調整して動かせる(水平スケーリング)ようになります.

Fault-tolerance - 対障害性

The unavoidable truth about software running in production is that things will go wrong. Even more when we take network, file systems and other third-party resources into account.

プロダクション環境でおかしなことが起こるのは避けようのない現実です.ネットワーク,ファイルシステム,その他第三者のリソースを考えに含めると,さらにおかしなことは増えます.

To cope with failures, Elixir provides supervisors which describe how to restart parts of your system when things go awry, going back to a known initial state that is guaranteed to work:

失敗になんとか対処するため,Elixir では,予定通りに物事がいかなくなったとき,あなたのシステムの一部をどのように再起動するかを決められるスーパーバイザーというものを提供しています.こうして動作が保証されていることが既にわかっている初期状態へと戻ります:

import Supervisor.Spec

children = [
  supervisor(TCP.Pool, []),
  worker(TCP.Acceptor, [4040])
]

Supervisor.start_link(children, strategy: :one_for_one)

Language features - 言語の特徴

Functional programming - 関数型プログラミング

Functional programming promotes a coding style that helps developers write code that is short, fast, and maintainable. For example, pattern matching allows developers to easily destructure data and access its contents:

関数型プログラミングは開発者がコードを短く,速く,メンテナンスしやすく書くための助けとなるようなコーディングスタイルを推奨します.例えば,パターンマッチングは開発者がデータ構造を解いて,中身へのアクセスを簡単にできるようにします:

%User{name: name, age: age} = User.get("John Doe")
name #=> "John Doe"

When mixed with guards, pattern matching allows us to elegantly match and assert specific conditions for some code to execute:

パターンマッチングをガードと一緒に使うと,いくつかのコードを実行するための具体的な条件を簡潔に示すことができます:

def serve_drinks(%User{age: age}) when age >= 21 do
  # Code that serves drinks!
  # お酒をお注ぎするコード!
end

serve_drinks User.get("John Doe")
#=> Fails if the user is under 21
#=> もし 21 以下なら失敗する

Elixir relies heavily on those features to ensure your software is working under the expected constraints. And when it is not, don't worry, supervisors got your back!

Elixir はあなたのソフトウェアが予想の範囲内で動作していることを確かめるため,これらの特徴に大きく頼っています.そして,想定外になったとき,ご心配なく,スーパーバイザーが引き戻してくれます!

Extensibility and DSLs - 拡張しやすさと DSL

Elixir has been designed to be extensible, letting developers naturally extend the language to particular domains, in order to increase their productivity.

Elixir は生産性の向上のため,開発者が特定の領域のために言語を自然に拡張できるよう,拡張しやすいように設計されています.

As an example, let's write a simple test case using Elixir's test framework called ExUnit:

例として,ExUnit と呼ばれる Elixir のテストフレームワークで単純なテストケースを書いてみましょう:

defmodule MathTest do
  use ExUnit.Case, async: true

  test "can add two numbers" do
    assert 1 + 1 == 2
  end
end

The async: true option allows tests to run in parallel, using as many CPU cores as possible, while the assert functionality can introspect your code, providing great reports in case of failures. Those features are built using Elixir macros, making it possible to add new constructs as if they were part of the language itself.

オプション async: true で,できるだけ複数の CPU コアを使ってテストを並列で走らせるようになり,assert 機能であなたのコードを検証し,失敗した場合はわかりやすいレポートを提供します.これらの特徴は Elixir のマクロを使って構築されており,まるでもともと言語の一部であるかのように新しい構文を追加できるようになっています.

Tooling features - ツールの特徴

A growing ecosystem - 成長するエコシステム

Elixir ships with a great set of tools to ease development. Mix is a build tool that allows you to easily create projects, manage tasks, run tests and more:

Elixir は開発を簡単にするための素晴しいツールセットを一緒に同梱しています.Mix はプロジェクトを作ったり,タスクを管理したり,テストをすることを簡単にできるようにするビルドツールです.

$ mix new my_app
$ cd my_app
$ mix test
.

Finished in 0.04 seconds (0.04s on load, 0.00s on tests)
1 tests, 0 failures

Mix is also able to manage dependencies and integrates nicely with the Hex package manager, which provides dependency resolution and the ability to remotely fetch packages.

Mix は依存性も管理でき,Hex というパッケージマネージャーとうまく統合されています.Hex では依存関係の解決やリモートにあるパッケージの取得を行えます.

Interactive development - 対話型開発

Tools like IEx (Elixir's interactive shell) are able to leverage many aspects of the language and platform to provide auto-complete, debugging tools, code reloading, as well as nicely formatted documentation:

IEx (Elixir の interactive shell) といったようなツールは言語を様々な観点でとらえるのに活用でき,フォーマットされたドキュメントと同じくらい良いものです.また,自動補完,デバッグツール,コード再読み込みなどをするためのプラットフォームとしても提供されています:

$ iex
Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help)
iex> c "my_file.ex"        # Compiles a file - ファイルをコンパイルする
iex> t Enum                # Prints types defined in the module Enum - Enum モジュールに定義されているタイプを表示する
iex> h IEx.pry             # Prints the documentation for IEx pry functionality - IEx の pry 関数のドキュメントを表示する

Erlang compatible - Erlang 互換

Elixir runs on the Erlang VM giving developers complete access to Erlang's ecosystem, used by companies like Heroku, Whatsapp, Klarna, Basho and many more to build distributed, fault-tolerant applications. An Elixir programmer can invoke any Erlang function with no runtime cost:

Elixir は Erlang VM 上で動作し,Erlang のエコシステムへ制限なしにアクセスできます.Erlang は Heroku, Whatsapp, Klarna, Basho などの会社で多くの分散,耐障害性の高いアプリケーションの構築に使われています.Elixir プログラマーは実行時コストなしにどんな Erlang の関数も呼び出すことができます.

iex> :crypto.md5("Using crypto from Erlang OTP")
<<192,223,75,115,...>>

To learn more about Elixir, check our getting started guide. We also have online documentation available and a Crash Course for Erlang developers.

もっと Elixir のことを知るには,getting started guide をご覧下さい.わたしたちはオンラインドキュメントErlang 開発者のための速修講座も用意しています.

86
76
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
86
76