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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
utagawa kiki
March 05, 2022
Programming
0
9.9k
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
Tweet
Share
More Decks by utagawa kiki
See All by utagawa kiki
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
1.9k
tparseでgo testの出力を見やすくする
utgwkk
2
610
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
4
1.1k
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
1.8k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
3.3k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
17k
Dive into gomock / Go Conference 2024
utgwkk
14
8.4k
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
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
Rで始めるML・LLM活用入門
wakamatsu_takumu
0
170
Windows on Ryzen and I
seosoft
0
230
Fundamentals of Software Engineering In the Age of AI
therealdanvega
1
240
今更考える「単一責任原則」 / Thinking about the Single Responsibility Principle
tooppoo
3
1.6k
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
550
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
600
AHC061解説
shun_pi
0
350
手戻りゼロ? Spec Driven Developmentとは@KAG AI week
tmhirai
1
190
AI時代のソフトウェア開発でも「人が仕様を書く」から始めよう-医療IT現場での実践とこれから
koukimiura
0
140
AIコーディングの理想と現実 2026 | AI Coding: Expectations vs. Reality 2026
tomohisa
0
1.2k
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.3k
Featured
See All Featured
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
0
450
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Thoughts on Productivity
jonyablonski
75
5.1k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
51k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
130
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
97
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
210
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
120
Designing for Performance
lara
611
70k
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プログラムとして解釈できる ◦
今後の課題: グラフ名を自由に指定できるようにする