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
YAGNIのお話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
chiroruxx
September 26, 2018
Programming
270
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
YAGNIのお話
9/26 php勉強会@東京
chiroruxx
September 26, 2018
More Decks by chiroruxx
See All by chiroruxx
Contextとはなにか
chiroruxx
1
460
初心者エンジニアから中級者エンジニアになるためにオススメの1冊
chiroruxx
0
140
Laravelのパッケージ全部紹介する
chiroruxx
2
150
Gopher のための「自由な話し合い」ワークショップ
chiroruxx
0
55
PHPをGoで動かす
chiroruxx
0
110
Goを使ってTDDを体験しよう!
chiroruxx
1
1.2k
今ならできる!PhpStormプラグイン開発
chiroruxx
0
120
Go Connectへの想い
chiroruxx
0
240
eBPF with PHPをさわる
chiroruxx
0
210
Other Decks in Programming
See All in Programming
AIエージェント時代のコードレビューを設計する
nogu66
6
2.6k
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
Deep dive into the select statement (GopherCon UK)
jespino
0
170
thread_parallel_with_free-threaded_Python_and_NumPy.pdf
riku_sakamoto
0
240
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
300
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
520
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
1.5k
Press start. Python's next generation.
willingc
PRO
3
320
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
230
コンパウンドプロダクト開発のためのローカルプロセスマネージャー再発明 #layerxgo
izumin5210
0
660
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
140
Featured
See All Featured
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
The Language of Interfaces
destraynor
162
27k
From π to Pie charts
rasagy
0
360
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
400
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Designing Experiences People Love
moore
143
24k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
KATA
mclloyd
PRO
35
15k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
210
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.7k
Transcript
YAGNIのお話 9/26 PHP勉強会@東京 前田 和人
PHPConference2018 スピーカー募 集中です!
自己紹介 ▪ 前田 和人 ▪ @chiroruxxxx ▪ 弁護士ドットコム株式会社
みなさんYAGNI知っていますか?
YAGNI実践してますか?
今回の内容 ▪ 私は、なるべくYAGNIを心がけていますが・・・ ▪ 結構むずかしい! ▪ 実際に開発していて、自分でハマりかけたYAGNIポイントを2つお伝えしてい きます! ▪ 熟練者の皆様はマサカリの準備をお願いいたします
ちなみにYAGNIとは ▪ “You ain’t gonna need it” ▪ (どうせ要らないって!) ▪
機能は実際に必要になるまで追加しないほうが良い ということ – 後で使う予定の機能の90%は実際に使用されない
実例
実例 ▪ CSVのダウンロード機能を新規に実装したい ▪ 別データのCSVダウンロード機能はすでに2つ存在している – しかも別々の実装で! ▪ ⇒CSVダウンロードの機能を1つにまとめ、かつ新規の機能も実装する
とりあえず共通化 class CsvBuilder{ public function build($items, array $header): string {
$stream = fopen('php://temp', 'w'); fputcsv($stream, $header); foreach ($items as $item) { fputcsv($stream, $item->toCsvRow()); } rewind($stream); return stream_get_contents($stream); } }
エンコーディング
エンコーディング ▪ 既存のCSVダウンロードの機能はUTF-8で出力している ▪ 新規に作るものは Shift-JISで出力してほしいらしい ▪ ⇒引数でエンコーディングをとればいんじゃね。汎用性ありそうだし ▪ 本日のYAGNIポイントその1
public function build( $items, array $header, string $to = 'SJIS’, string $from = ‘UTF-8’ ): string{/* … */}
YAGNIポイント1 ▪ そもそもデフォルトの文字コードがUTF-8から外れるようなシステムではない ▪ エンコーディング先もShift-JISにするか、そのままのどちらかしか現状は考え られない ▪ 考えることがいっぱいありそう – fromとtoが同じ場合でもmb_convert_encoding走らせるの?
– 不正な文字コードが来た場合は? ▪ ⇒今回のケースでは、「エンコードを変換するか?」だけ指定できれば良かっ たことに気づく
YAGNIポイント1 public function build($items, array $header, bool $convert = false):
string { $stream = fopen('php://temp', 'w'); fputcsv($stream, $header); foreach ($items as $item) { fputcsv($stream, $item->toCsvRow()); } rewind($stream); $contents = stream_get_contents($stream); if ($convert) { return mb_convert_encoding($contents, 'SJIS', 'UTF-8'); } return $contents; }
ヘッダー
ヘッダー ▪ 今回は人がエクセルで読むようなCSVを作る ▪ 機械が読む場合、ヘッダー(タイトル)行は不要な場合は多い ▪ どちらにも対応できるように、ヘッダーは設定なしにできるほうがいいのか? public function build($items,
array $header = [], bool $convert = false): string { // ... if (count($header) > 0) { fputcsv($stream, $header); } // ... }
YAGNIポイント2 ▪ 作ったところでいったいいつ使われるのか・・・ ▪ 保守性が下がる – 「機械が読めるように処理が工夫されている」 – ⇒「このCSVで外部連携されてる可能性が高い」 –
⇒「変更するなら調査せねば」 – ⇒「・・・外部連携されてないじゃないか!」 ▪ 今回のケースでは、コードの修正なし
まとめ
YAGNIとは ▪ “You ain’t gonna need it” ▪ (どうせ要らないって!) ▪
つまり、実装のコスト支払いをできる限り遅らせる取り組み ▪ XPのスローガンの「なんとか動いて、最も無駄のないものを作れ」を支えるプ ラクティスのひとつ
YAGNIをするとどうなるか ▪ 無駄な抽象度がなくなる – コードが限定的になり読みやすくなる ▪ ユニットテストがシンプルになる ▪ コード量が無駄に増えない –
“コードをできるだけ小さく軽量に維持すること”(リーダブルコード)
YAGNIポイント ▪ 以下のようなものを作ろうとしたときには「本当に必要?」と自問しよう – フレームワーク – 再利用可能なコンポーネント – フレキシブルな設計 ▪
エンジニアはキラキラした言葉に踊らされやすい ▪ パターンが使えるときも注意 – 必要ないのにコンストラクタインジェクションしてるコードはよく見かけ る ▪ ⇒本当に価値のあるものを作ろう