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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
utagawa kiki
March 05, 2022
Programming
10k
0
Share
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
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
3.6k
tparseでgo testの出力を見やすくする
utgwkk
2
1.5k
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
4
1.9k
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
2.7k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
4.2k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
17k
Dive into gomock / Go Conference 2024
utgwkk
14
8.5k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.7k
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
utgwkk
7
4.3k
Other Decks in Programming
See All in Programming
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
0
130
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
300
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
340
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
380
2026-03-27 #terminalnight 変数展開とコマンド展開でターミナル作業をスマートにする方法
masasuzu
0
320
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
260
Vibe NLP for Applied NLP
inesmontani
PRO
0
320
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
840
事業会社でのセキュリティ長期インターンについて
masachikaura
0
240
煩雑なSkills管理をSoC(関心の分離)により解決する――関心を分離し、プロンプトを部品として育てるためのOSSを作った話 / Solving Complex Skills Management Through SoC (Separation of Concerns)
nrslib
4
860
GNU Makeの使い方 / How to use GNU Make
kaityo256
PRO
16
5.6k
Coding at the Speed of Thought: The New Era of Symfony Docker
dunglas
0
4.8k
Featured
See All Featured
Tell your own story through comics
letsgokoyo
1
890
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.1k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
97
The Curious Case for Waylosing
cassininazir
0
300
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.1k
How to Think Like a Performance Engineer
csswizardry
28
2.5k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
400
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
520
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プログラムとして解釈できる ◦
今後の課題: グラフ名を自由に指定できるようにする