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
prototypeとjust epic. と私 / YAPC::Japan::Online 2022
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
utagawa kiki
March 05, 2022
Programming
10k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
prototypeとjust epic. と私 / YAPC::Japan::Online 2022
YAPC::Japan::Online 2022 LT
解説記事:
https://blog.utgw.net/entry/2022/03/05/191709
utagawa kiki
March 05, 2022
More Decks by utagawa kiki
See All by utagawa kiki
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
2
1.3k
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
4.5k
tparseでgo testの出力を見やすくする
utgwkk
2
2.1k
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
4
2.6k
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
3.3k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
4.6k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
17k
Dive into gomock / Go Conference 2024
utgwkk
14
8.8k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.8k
Other Decks in Programming
See All in Programming
今さら聞けない .NET CLI
htkym
0
200
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
520
【QA Test Talk Vol.8】AI-DLC による Whole Team Approach の加速
pkshadeck
PRO
0
190
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
700
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
500
生成AIで帳票OCRが「簡単に」作れる時代になった?
kon_shou
0
1k
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
240
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
200
FDEが実現するAI駆動経営の現在地
gonta
2
280
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
380
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
320
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
1
980
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.5k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
3
440
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
480
Raft: Consensus for Rubyists
vanstee
141
7.6k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
650
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
Facilitating Awesome Meetings
lara
57
7.1k
Scaling GitHub
holman
464
140k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Transcript
prototypeとjust epic. と私 YAPC::Japan::Online 2022 @utgwkk
自己紹介 • @utgwkk (うたがわきき) • 株式会社はてな Webアプリケーションエンジニア • KMC (京大マイコンクラブ)
• 最近はTypeScriptを書いています
好きなPerlの言語機能 • wantarray関数 ◦ 3値を返す関数なので • DESTROYメソッド ◦ オブジェクトの解放に処理を差し込めて便利 ◦
今後はdeferでやる方向になる? • prototype ◦ 今日は主にこれの話をします • 他にいい言語機能があれば教えてください!!
prototypeとは • サブルーチンの引数の解釈方法を制御できる ◦ パーサの挙動が変わる!! • 書き方 ◦ sub name
(ここに記号をいろいろ書く) ◦ sub name : prototype(ここに記号をいろいろ書く) ◦ サブルーチンシグネチャのことを考えると後者の書き方がよさそう
prototypeの例 sub foo ($) { } sub bar ($;$@) {
} sub mymap (&@) { } sub zip (\@\@) { } zip @xs, @ys; sub foo () { 1 }
prototypeの読み方 (残りはperldoc perlsubで) sub foo ($) { } # 括弧の中に記号を書く
sub bar ($;$@) { } # ; 以降は省略可能 sub mymap (&@) { } # &はサブルーチン、@はリスト sub zip (\@\@) { } # リストをリファレンスとして受ける zip @xs, @ys; sub foo () { 1 } # 定数をreturnなしで返すとインライン展開される
身近に潜むprototype採用事例 (Try::Tiny) try { } catch { }; sub try
(\&;@) try-catch構文をprototypeで再現 (末尾のセミコロンが必要) 最新のPerlではtry-catch構文が組み込まれている (こっちもセミコロン不要)
身近に潜むprototype採用事例 (Test2::V0) is $obj, object { prop isa => 'Foo';
call meth => 'blah'; }; $obj の性質を宣言的にテストできる
身近に潜むprototype採用事例 (List::MoreUtils) zip6 @xs, @ys, @zs; sub zip6 (\@\@;\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\@\ @\@\@\@\@)
# \@ が32個 一番好きなprototypeです
リストを33個渡すと……?? use List::MoreUtils qw(zip6); my @x = (1); zip6 @x,
@x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x, @x; # @x が33個 Too many arguments for List::MoreUtils::XS::zip6 at zip6.pl line 6, near "@x;
prototype (+α) 活用事例
just epic. “just epic”と書くだけでサーバを起動する方法 - Hatena Developer Blog just epic.
2011-2022;
とりあえずDeparse % perl -MO=Deparse -e 'just epic. 2011-2022;' 'epic'->just .
'2011' - 2022; -e syntax OK
間接オブジェクト記法 • b A と書いたら A->b と解釈される ◦ Foo->new() を
new Foo() って書ける • just epicでepicパッケージのjustメソッドを呼び出している • 新しめのPerl (>= 5.32) では no feature 'indirect'; で無効化できる • print STDERR "YO" のような記法はno feature 'indirect' 下でも書ける
just epic? no feature 'indirect'; just epic. 2011-2022; sub epic::just
{ } Unquoted string "just" may clash with future reserved word at - line 2. (中略)
作戦 • just, epic というサブルーチンをそれぞれ用意する • 警告ゼロを目指す ◦ use strict;
use warnings; は義務 ◦ no warnings; も使わずに済ませたい
just epic. (間接オブジェクト記法なし) no feature 'indirect'; sub just ($) {}
# ここでサーバーを起動する sub epic () { return 1 } just epic. 2011-2022;
prototypeなしでもOK no feature 'indirect'; sub just {} sub epic {
1 } just epic. 2011-2022; Deparseしたときの美しさはこっちの方が高いかも?
Webサーバーを起動する • https://gist.github.com/utgwkk/febc9e199ecc3c44eb987ea2a913a461 • ここでデモ
dot言語 (graphviz) https://blog.utgw.net/entry/2021/10/19/221139 digraph haisen { 電子レンジラック -> 手前コンセント; 冷蔵庫
-> 手前コンセント; …; }
もしかしてこれはPerlでは??? https://blog.utgw.net/entry/2021/10/19/221139 digraph haisen { 電子レンジラック -> 手前コンセント; 冷蔵庫 ->
手前コンセント; …; }
方針 • Perlプログラムの中にdot言語のコードを埋め込む • Perlとして実行したらdot言語のコードが出力される
適切なprototypeを設定する sub digraph ($) { } sub haisen (&) {
} これで digraph haisen { … } と書ける
メソッド呼び出しをハンドリングする sub UNIVERSAL::AUTOLOAD { … } あらゆるモジュールの (UNIVERSAL) 存在しないメソッド呼び出しをハンドリング (AUTOLOAD)
(モジュール名)::(メソッド名) を (モジュール名) -> (メソッド名) に変える
できたもの • https://gist.github.com/utgwkk/47140c80b7a61fbdb6656c7d4ea29ae0 • ここでデモ • perl dot.pl | dot
-Tpng -oout.png
まとめ • prototypeを使うといろんなことが実現できる • just epic. を間接オブジェクト記法なしで書ける • dot言語をPerlプログラムとして解釈できる ◦
今後の課題: グラフ名を自由に指定できるようにする