Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
IEx maniacs
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
ohr486
December 26, 2021
Programming
660
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
IEx maniacs
https://beam-lang.connpass.com/event/232202/
ohr486
December 26, 2021
More Decks by ohr486
See All by ohr486
負荷試験Night#1 負荷試験2023年トレンド
ohr486
17
4.9k
Elixir/PhoenixによるWeb開発の現場から
ohr486
1
650
Hacking Phoenix Performance
ohr486
1
410
Plug & WAF
ohr486
2
550
elixirをプロダクションに導入する
ohr486
1
730
Hack and Read Elixir
ohr486
2
810
Running App on AppRunner
ohr486
0
860
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
910
ex-app-on-k8s
ohr486
0
270
Other Decks in Programming
See All in Programming
Lessons from Spec-Driven Development
simas
PRO
0
170
The Arts and Crafts of Work in the AI Era — Toward Mastery in Software Development
kuranuki
1
750
Modding RubyKaigi for Myself
yui_knk
0
920
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
710
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
800
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
680
Swiftのレキシカルスコープ管理
kntkymt
0
220
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
JavaDoc 再入門
nagise
0
320
AI時代のUIはどこへ行く?その2!
yusukebe
21
7k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4k
Featured
See All Featured
Optimizing for Happiness
mojombo
378
71k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
RailsConf 2023
tenderlove
30
1.5k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Color Theory Basics | Prateek | Gurzu
gurzu
0
360
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
430
Testing 201, or: Great Expectations
jmmastey
46
8.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Prompt Engineering for Job Search
mfonobong
0
340
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
300
Transcript
IEx maniacs 2021-12-26 tokyo.ex #14
agenda • About Me • ゴール • モチベーション • iexの設定方法
• iexのショートカット(ヘルパー) • debugging with iex • まとめ
About Me • おーはら / Twitter: @ohrdev / Github: ohr486
• 株式会社ドリコム SRE部 部長 ◦ Work: ▪ エンジニアマネージャ • 技術戦略の策定/推進 • エンジニア採用/採用戦略策定 ▪ サーバー/インフラエンジニア • 開発現場でゲームのバックエンド (Rails/Phoenix/Go/HCL)のコード書いてます ▪ 新規事業/ディレクター • 負荷試験支援/DevOps推進支援/設計コンサル • Community ◦ tokyo.ex / Japan Elixir Association / Erlang&Elixir Fest • Hobby ◦ 仏像制作 ◦ 自転車
ゴール • ターゲット ◦ iexをもっと便利に使いたい人 ◦ iexを使ってdebugを効率的に行いたい人 • 今日のゴール ◦
iexの設定方法を理解する ◦ iexの便利な使い方を理解する
モチベーション • iexを活用することで生活レベル(=debug効率)が上がった • iexのコードを読んだ/hackした時の気付きが多かった ◦ https://blog.ohr486.net/2021/12/18/iex-inside/
iexの設定方法 • 設定ファイルは以下 ◦ (ホームディレクトリ) / .iex.exs ◦ (プロジェクトディレクトリ )
/ .iex.exs • ファイル探索の優先度 ◦ (1) ホームディレクトリに .iex.exsが無いかチェック ◦ (2) ホームディレクトリになければプロジェクトディレクトリが .iex.exsが無いかチェック • .iex.exsでは、任意のelixirのコードを実行可能 • import_fileで任意のファイルを読み込んで、記述されているelixirコードを実行可能 • iexのヘルパーも実行可能 ◦ プロジェクトディレクトリの .iex.exsからホームディレクトリの .iex.exsを読み込む等ができる • IEx.configure で動的に設定を変更可能 ◦ IEx.configure( 設定項目: 設定値 )
iexの設定方法 • プロンプト表示 : ◦ 色関連の設定: https://hexdocs.pm/elixir/IO.ANSI.html#functions ◦ default_prompt :
文字列を指定 IO.ANSI利用の為 文字列でもOK
iexの設定方法 • 複数行入力時のプロンプト表示 ◦ continuation_prompt : 文字列を設定 ▪ デフォルト: %prefix
部分のみが ドット(.) に差し代わる
iexの設定方法 • 複数行入力時のプロンプト表示 ◦ continuation_prompt : 文字列を設定
iexの設定方法 • 画面表示幅 ◦ width : 横幅の上限
iexの設定方法 • 返り値の表示 ◦ inspect : https://hexdocs.pm/elixir/Inspect.Opts.html ▪ limit :
タプル,Map,Bitstring,List等のコレクションの表示要素数の上限
iexの設定方法 • 返り値の表示 ◦ inspect : https://hexdocs.pm/elixir/Inspect.Opts.html ▪ pretty :
適当な幅でで改行を入れるかどうか
iexの設定方法 • 履歴保持数(後述する vヘルパー での評価値の履歴数) ◦ history_size : 保持履歴数
iexの設定方法 • 色設定 : https://hexdocs.pm/elixir/IO.ANSI.html#functions ◦ colors : ▪ eval_interrupt
: eval時のinterupt / デフォルト: yellow ▪ eval_result : evalの結果表示 / デフォルト: yellow ▪ eval_error : eval時のエラー表示 / デフォルト: red ▪ eval_info : eval時のinfo表示 / デフォルト: normal ▪ stack_info : stack情報表示 / デフォルト: red ▪ blame_diff : blameのdiff表示 / デフォルト: red ▪ ls_directory : ls時のディレクトリ表示 / デフォルト: blue ▪ ls_device : ls時のデバイス表示 / デフォルト: green ▪ syntax_colors • atom: atom型データの表示 / デフォルト: cyan • string : string型データの表示 / デフォルト: green • list : list型データの表示 / デフォルト: default_color • boolean: ブール型データの表示 / デフォルト: magenta • nil : nil型データの表示 / デフォルト: magenta • tuple : tuple型データの表示 / デフォルト: default_color • binary : バイナリデータの表示 / デフォルト: default_color • map : map型データの表示 / デフォルト: default_color
iexの設定方法 • 現在の設定状態の表示 ◦ IEx.configuration
iexの設定方法 • DEMO-1 ◦ ホームディレクトリの.iex.exsを読み込み ◦ 起動時にメッセージをクリア ◦ 起動メッセージを表示
iexのショートカット(ヘルパー) • helpers参照 ◦ https://github.com/elixir-lang/elixir/blob/main/lib/iex/lib/iex/helpers.ex • よく使うもの(1) ◦ 表示 ▪
clear() : ターミナルをクリア ▪ i(対象のvalue) : 対象の値の情報を表示 ▪ h(モジュール/関数/マクロ) : 対象のモジュール/関数/マクロの情報を表示 ▪ exports(モジュール) : 対象モジュールが公開している関数 /マクロを表示 ▪ ls() : 現在のディレクトリのファイルを表示 ▪ pwd() : 現在のディレクトリパスを表示 ◦ コンパイル ▪ recompile() : プロジェクトのコードを recompileしてロード ▪ c(ファイル) : 対象のファイルをコンパイル ▪ r(モジュール) : 対象のモジュールのソースコードをコンパイル
iexのショートカット(ヘルパー) • よく使うもの(2) ◦ REPL ▪ #iex:break : 行を跨いだ入力時に、入力をとりやめる
iexのショートカット(ヘルパー) • よく使うもの(3) ◦ プロセス ▪ pid(文字列) : 文字列のIDでプロセスIDを作成 ▪
pid(int, int, int) : 引数の数字でプロセス IDを作成 ※ port, refも同様
iexのショートカット(ヘルパー) • よく使うもの(3) ◦ 履歴 ▪ v() : 最後に評価された値を返却 ▪
v(n) : n番目の履歴(カウンタがn)の値を返却 ▪ v(-m) : m個前の履歴の値を返却
iexのショートカット(ヘルパー) • よく使うもの(4) ◦ 履歴(パイプ演算子) ▪ vを使って最後に評価した値を呼び出すことができた ▪ 行の冒頭でパイプ演算子を使うと、 vの値(最後に評価された値
)を入力として取れる
iexのショートカット(ヘルパー) • DEMO-2 ◦ 1 + 1 の評価を、iex上で再現 ◦ 文字列
-> トークン -> パース -> eval の一連の流れをelixirモジュールを使っ て実行
Code (charlist) Tokens Forms (quoted) tokenize parse Result eval Code
(string) String.to_charlist “ 1 + 1 “ ‘ 1 + 1 ‘ [ {:int, {1, 1, 1}, ‘1’}, {:dual_op, {1, 3, nil}, :+}, {:int, {1, 5, 1}, ‘1’} ] {:+, [line: 1], [1, 1]} 2 :elixir.string_to_tokens (clist, line, col, file, binds) :elixir.tokens_to_quoted (tokens, binds, env) :elixir.eval_forms (forms, binds, env)
debugging with iex • iexによる主なデバッグ方法 ◦ 古き良き時代のprintdebug(コードにIO.print, IO.inspect を差し込んで値を表示) ◦
ソースコードにIEx.pryを差し込んで、プログラムの途中で内部情報を確認 ◦ 特定の関数がcallされたタイミングでブレイクポイントを挿入、 IEx.pryで内部情報を確認 ◦ REPL上でヘルパーを駆使して処理を再現
debugging with iex • IEx.pry ◦ コードに「 require IEx; IEx.pry
」を記述すると、その行に到達した箇所で pryのREPLに入る ◦ respawn(): pryのREPLから出る ◦ whereami(): IEx.pry周辺のコードを表示 ◦ whereami(N): IEx.pry周辺のコードの前後 N行を表示
debugging with iex • break! ( Module, Function, Arity, break回数
) ◦ Module.Function/Arity の関数実行時に、break回数 だけbreakしてpryに入る
debugging with iex • DEMO-3 ◦ IEx.pryをコードに差し込んでpryを起動 ◦ 前後のコードを表示 ◦
pry挿入箇所のスコープでREPL ◦ respawnでpryから抜ける ◦ break!で特定の関数を実行したタイミングでpryを起動
まとめ • iexの設定ファイル(.iex.exs)について紹介しました • iexの設定項目を紹介しました • pry,breakを使ったiex上でのdebug方法を紹介しました • 参考情報 ◦
https://github.com/blackode/elixir-tips ◦ https://github.com/blackode/elixir-tips/blob/master/part2.md ◦ https://github.com/elixir-lang/elixir/blob/main/lib/iex/lib/iex/helpers.ex ◦ https://medium.com/blackode/custom-iex-prompt-elixir-c95b7f5bf8c3