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
680
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
890
sponsor-talk-drecom-heisei-ruby-kaigi
ohr486
0
930
ex-app-on-k8s
ohr486
0
280
Other Decks in Programming
See All in Programming
Intent as Code
shoppingjaws
6
1.1k
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
770
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
430
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
560
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.5k
Ghostty + Neovimで作る 透明でカッコ良い開発環境
j341nono
0
150
Agents on Rails - Rails at Scale 2026
irinanazarova
0
300
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
180
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
460
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
510
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
310
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
270
Featured
See All Featured
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.2k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
250
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Raft: Consensus for Rubyists
vanstee
142
7.7k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
690
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Utilizing Notion as your number one productivity tool
mfonobong
4
600
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
600
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