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
Perlのよい書き方
Search
dorapon2000
July 01, 2020
Programming
190
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Perlのよい書き方
#perlwalateの発表で使用したスライドです。
perlstyleとPerl Best Practceの話
dorapon2000
July 01, 2020
More Decks by dorapon2000
See All by dorapon2000
Try::Tiny再入門
dorapon2000
0
370
ns-3.29でモジュール開発
dorapon2000
0
1.4k
Other Decks in Programming
See All in Programming
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
190
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.6k
【加筆修正版】Laravel のアプリケーションをどこにデプロイするか #phpcon_ehime
akase244
0
150
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
270
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
AWSに止められる覚悟してますか?
morizo_1984
2
540
Railsバージョンを4倍にした話
optim
0
390
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
Vue Fes Japan の “作る側”に関わってみて
naokihaba
0
160
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Domain-Driven Transformation
hschwentner
2
2.3k
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
How STYLIGHT went responsive
nonsquared
100
6.3k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
A Tale of Four Properties
chriscoyier
163
24k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
410
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
Done Done
chrislema
187
17k
Technical Leadership for Architectural Decision Making
baasie
3
600
Prompt Engineering for Job Search
mfonobong
0
520
Transcript
Perlのよい書き方 Perl若手の会 (2020/07/01) dorapon2000
% whoami 久保田享祐 / dorapon2000 - 筑波大学大学院 → モバイルファクトリー - 新卒3ヶ月目 -
Perlは入社が決まってから触り始めた - Python - 最近の趣味 - Apex - 競プロ - みんはや - プライムビデオ
とつぜんですが、 未完了、あるいは結果が許容値を下回る場合、次のクライアントへ なにかがおかしい? next CLIENT if not $finished || $result
< $MIN_ACCEPTABLE;
こう書くとどうでしょうか - not は || よりも演算子の優先度が低い - ! と not
は演算子の優先度が異なる - 思い違いから意図しない挙動に next CLIENT if not ($finished || $result < $MIN_ACCEPTABLE);
Perlベストプラクティス - ! は古くから使われるブール演算子で馴染みが深い - 書き手と読み手どちらにも思い違いが起きないように、and/not は いっさい使用しないようにする next CLIENT
if !$finished || $result < $MIN_ACCEPTABLE; Perlベストプラクティス p.76
紹介するもの - % perldoc perlstyle - https://perldoc.jp/docs/perl/5.26.1/perlstyle.pod - Perlの文化を知れる -
Perl Best Practice - https://www.amazon.co.jp/dp/4873113008/ - 業務中の悩みの答えになる
⚠注意 - あくまで指標 - チームや自分にあったものを選びましょう
perlstyle - Perlスタイルガイド • 4 カラムのインデント。 • 可能なら、開始中かっことキーワードを同一行に; そうでなければ、開始をそろえる。 •
複数行 BLOCK の開始中かっこの前にスペース。 • 1 行の BLOCK は中かっこも含め、1 行で。 • セミコロンの前に空白なし。 • "短い" 1 行 BLOCK ではセミコロンを省略。※ • ほとんどの演算子の前後にはスペース。 • "複雑な"代入(ブラケット内)の前後にはスペース。 • 異なることをするチャンクの間には空行。 • else をくっつけない。 • 関数名と開始カッコの間にはスペースなし。 • カンマの後ろにはスペース。 • 長い行は、演算子の後ろで改行する(and と or を除く)。※ • 行の最後のカッコの後ろにスペース。 • 対応する要素の開始位置をそろえる。 • 冗長な表現は、わかりにくくならない限りは省略する。
複数行 BLOCK の開始中かっこの前にスペース for my $name (@names) { ... }
for my $name (@names){ ... } PBPはK&Rスタイ ルを推奨 for ... { BSD }
else をくっつけない。 } else { ... ... } else {
... 未だに慣れない
長い行は、演算子の後ろで改行する push @steps, $steps[-1] + $radial_velocity * $elpased_time + $orbital_velocity
* ($phase + $phase_shift) - $DRAG_COEFF * $altitude push @steps, $steps[-1] + $radial_velocity * $elpased_time + $orbital_velocity * ($phase + $phase_shift) - $DRAG_COEFF * $altitude; PBP perlstyle PBP
対応する要素の開始位置をそろえる。 $name = standardize_name($name); $age = time - $birth_date; $status
= ‘active’; $name = standardize_name($name); $age = time - $birth_date; $status = ‘active’; とても見やすい
主要部を前に open(FOO,$foo) || die "Can't open $foo: $!"; die "Can't
open $foo: $!" unless open(FOO,$foo); 主要部が 前! or も可
ループのラベルは積極的に使う LINE: for (;;) { statements; last LINE if $foo;
next LINE if /^#/; statements; } - lastはアウトデント - ループのラベルは積極的に使う perlstyleとPBPの両方 で紹介されている
PBPで紹介されているもの - 長い代入式は代入演算子の前で分割する - サブルーチンを後続の開きカッコから分離しない $preficted_val = $average + predicted_change
* $fudge_factor; 2行目が前の続きとす ぐわかる my @candidates = get_candidates($marker); 制御構文は前後に空白を入れ るため、見た目で関数だとわか る
良いコードの手助けをするツール - Perl::Critic; - 構文チェック - Perl::Tidy; - 自動整形 -
-pbpオプションでPBPの形式にしてくれる 各種エディタの拡張機能と合わせることができる
まとめ - つねに一貫性を。 - 常に素敵に。
ご清聴ありがとうございました よいPerlライフを!