Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
IEx maniacs
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
ohr486
December 26, 2021
Programming
700
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
670
Hacking Phoenix Performance
ohr486
1
430
Plug & WAF
ohr486
2
570
elixirをプロダクションに導入する
ohr486
1
760
Hack and Read Elixir
ohr486
2
830
Running App on AppRunner
ohr486
0
880
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
930
ex-app-on-k8s
ohr486
0
280
Other Decks in Programming
See All in Programming
AGENTS.md Is Not Enough:Build Skills, Don't Download Them
lx_t
0
130
スマート反転とウェブアクセシビリティ
camiha
0
210
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
190
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
290
Kiroで創り、AgentCoreで繋ぐ!AWSで実践する「AI-DLC」から「AIエージェント統合」までの最新地図
licux
4
800
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
520
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
390
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
520
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3.2k
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
210
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
0
1.8k
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
530
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Prompt Engineering for Job Search
mfonobong
0
460
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
440
The World Runs on Bad Software
bkeepers
PRO
72
12k
Designing for Timeless Needs
cassininazir
1
510
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
How to Ace a Technical Interview
jacobian
281
24k
Scaling GitHub
holman
464
140k
Done Done
chrislema
187
17k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
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