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
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
470
初心者エンジニアから中級者エンジニアになるためにオススメの1冊
chiroruxx
0
150
Laravelのパッケージ全部紹介する
chiroruxx
2
160
Gopher のための「自由な話し合い」ワークショップ
chiroruxx
0
56
PHPをGoで動かす
chiroruxx
0
120
Goを使ってTDDを体験しよう!
chiroruxx
1
1.4k
今ならできる!PhpStormプラグイン開発
chiroruxx
0
130
Go Connectへの想い
chiroruxx
0
250
eBPF with PHPをさわる
chiroruxx
0
210
Other Decks in Programming
See All in Programming
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
260
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.3k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Rails World 2026, Austin, Texas
marcoroth
0
160
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
120
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
110
Are APIs Still Relevant in the AI Era?
soyuka
0
410
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
4k
APNsからLive Activityを開始する話
yumnumm
0
150
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
スマートフォンでモールス信号を送受信する 〜スマートフォンのLEDとカメラで作る光通信の設計と実装〜
atsuki_seo
0
230
すこし踏み込む CancellationToken
htkym
2
1.6k
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
600
Featured
See All Featured
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
390
エンジニアに許された特別な時間の終わり
watany
109
250k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Unsuck your backbone
ammeep
672
58k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
The Curious Case for Waylosing
cassininazir
1
550
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The agentic SEO stack - context over prompts
schlessera
0
950
Code Reviewing Like a Champion
maltzj
528
40k
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ポイント ▪ 以下のようなものを作ろうとしたときには「本当に必要?」と自問しよう – フレームワーク – 再利用可能なコンポーネント – フレキシブルな設計 ▪
エンジニアはキラキラした言葉に踊らされやすい ▪ パターンが使えるときも注意 – 必要ないのにコンストラクタインジェクションしてるコードはよく見かけ る ▪ ⇒本当に価値のあるものを作ろう