LoginSignup
8
0

自衛官からエンジニアへ Elixirから始める Web開発 Part27(Phoenix編)

Posted at

この記事は「Elixir Advent Calendar 2023」のvol27の記事です
東京にいるけどfukuokaexのYOSUKEです。

普段は 合同会社TheWaggle で教材開発・システム開発・研修講師などマルチに活動してます。

このシリーズでは、文系ですらない、体育会系でも始められるプログラミング学習 というテーマで元自衛官だった僕が
自衛官からエンジニアになってもらいたいという気持ちを込めて、普段は大人しいですが、このコラムシリーズでは、あえて、体育会系のノリで、貴様ら理屈で覚えるなら体で覚えろ!というノリで書いてみたいと思います。

なので、初学者向けですが、理論は後回し、まずは動かして体感しろってノリの第27回目です。

それでは、いくぞ!

環境を作るのは、不死鳥のごとく

いいか、貴様ら、今日からいよいよ、Web開発に入ってく!だが、しかし貴様らには教えなければならない基礎はまだまだ多い!

だが、完璧に基礎を理解してからなどゆとりがあると思うな!戦場においても人は大勢死に常に人手不足が当たり前!
昨日入った新兵が3ヶ月生き残っただけで、部隊を任されるくらい人手不足だ!

そうだ、Livebookを使って関数を作ってきたが、それは訓練の中の生ぬるい環境の中でやってきたことに過ぎん!
これからが本番だ!

そうと決まれば、早速 Web開発の準備をする。

まずは、貴様らのMacに開発環境をインストールする。

今回はElixirのインストールだけではなく、Phoenixframeworkもインストールする。

何? frameworkとは何か?だと、貴様らがこれを理解するには早すぎる。今のところは、frameworkとは特殊部隊のようなものだと思え、専門分野に特化して訓練を積んだ手だれの集団だ、今回のPhoenixframeworkはElixir部隊におけるWebを攻略するための特殊部隊

Phoenix部隊だ!

Phoenix部隊の特徴は大まかに言えば、以下の通りだ

高性能: 高い並列処理能力と耐障害性を備えたErlang部隊による下支えがあり。多くのユーザーに同時にサービスを提供できる能力を意味する。

リアルタイム通信: PhoenixはWebSocketsを使ったリアルタイム通信を簡単に実装できる。これにより、チャットアプリやライブアップデートなど、リアルタイムのインタラクションが求められるアプリケーションに適している。

生産性: Elixir言語の機能を活用し、開発者が効率的にコードを書くことを可能にする。また、MVC(モデル-ビュー-コントローラー)アーキテクチャを採用しており、ウェブアプリケーションの開発を構造的に行える。

これらの特徴を備えた特殊部隊が支援してくれる為、貴様のような新兵でも、高度な作戦の一端を担えるようになるわけだ。

インストールは公式リファレンスの以下のページにある。上から順に読んだまま実行すれば完了だ。

公式リファレンスでもわからないだと! 貴様の目は節穴か! いいだろう、そんな奴はfukuoka.exのコミュニティやpiyopiyo.exに参加してわからない所を手取り足取り教えてもらうといい!

無事にインストールできたかどうかは、次のコマンドをターミナルを実行して叩いてみろ!

iex
Erlang/OTP 26 [erts-14.0.2] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit] [dtrace]

Interactive Elixir (1.15.7) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> 

上記が表示されたら、 Ctr + Cを2回で終了
続いて、 以下のコマンドを叩いてみろ!

mix help

mix                   # Runs the default task (current: "mix run")
mix app.config        # Configures all registered apps
mix app.start         # Starts all registered apps
mix app.tree          # Prints the application tree
mix archive           # Lists installed archives
mix archive.build     # Archives this project into a .ez file
mix archive.install   # Installs an archive locally
mix archive.uninstall # Uninstalls archives
mix clean             # Deletes generated application files
mix cmd               # Executes the given command
mix compile           # Compiles source files
mix deps              # Lists dependencies and their status
mix deps.clean        # Deletes the given dependencies' files
mix deps.compile      # Compiles dependencies
mix deps.get          # Gets all out of date dependencies
mix deps.tree         # Prints the dependency tree
mix deps.unlock       # Unlocks the given dependencies
mix deps.update       # Updates the given dependencies
mix do                # Executes the tasks separated by plus
mix escript           # Lists installed escripts
mix escript.build     # Builds an escript for the project
mix escript.install   # Installs an escript locally
mix escript.uninstall # Uninstalls escripts
mix eval              # Evaluates the given code
mix format            # Formats the given files/patterns
mix help              # Prints help information for tasks
mix hex               # Prints Hex help information
mix hex.audit         # Shows retired Hex deps for the current project
mix hex.build         # Builds a new package version locally
mix hex.config        # Reads, updates or deletes local Hex config
mix hex.docs          # Fetches or opens documentation of a package
mix hex.info          # Prints Hex information
mix hex.organization  # Manages Hex.pm organizations
mix hex.outdated      # Shows outdated Hex deps for the current project
mix hex.owner         # Manages Hex package ownership
mix hex.package       # Fetches or diffs packages
mix hex.publish       # Publishes a new package version
mix hex.registry      # Manages local Hex registries
mix hex.repo          # Manages Hex repositories
mix hex.retire        # Retires a package version
mix hex.search        # Searches for package names
mix hex.sponsor       # Show Hex packages accepting sponsorships
mix hex.user          # Manages your Hex user account
mix loadconfig        # Loads and persists the given configuration
mix local             # Lists tasks installed locally via archives
mix local.hex         # Installs Hex locally
mix local.phx         # Updates the Phoenix project generator locally
mix local.public_keys # Manages public keys
mix local.rebar       # Installs Rebar locally
mix new               # Creates a new Elixir project
mix phx.new           # Creates a new Phoenix v1.7.10 application
mix phx.new.ecto      # Creates a new Ecto project within an umbrella project
mix phx.new.web       # Creates a new Phoenix web project within an umbrella project
mix profile.cprof     # Profiles the given file or expression with cprof
mix profile.eprof     # Profiles the given file or expression with eprof
mix profile.fprof     # Profiles the given file or expression with fprof
mix release           # Assembles a self-contained release
mix release.init      # Generates sample files for releases
mix run               # Runs the current application
mix test              # Runs a project's tests
mix test.coverage     # Build report from exported test coverage
mix xref              # Prints cross reference information
iex -S mix            # Starts IEx and runs the default task

このように mixから始まる号令集が見られる

この状態までできたら一旦は、準備完了だ。

いいか、貴様ら次回からはPhoenix部隊と合同演習に入る! その際に下手な詮索は禁物だ!
貴様らに理解するにはまだ早い。こうしたらこうなると言うルールベースでまずは覚えろ!

わかったな!

今日はここまで、それでは次回 Part28でまた会おう!

8
0
0

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
8
0