Skip to Content
Tidy First? ―個人で実践する経験主義的ソフトウェア設計
book

Tidy First? ―個人で実践する経験主義的ソフトウェア設計

by Kent Beck, 吉羽 龍太郎, 永瀬 美穂, 細澤 あゆみ
December 2024
Beginner to intermediate
164 pages
1h 15m
Japanese
O'Reilly Japan, Inc.
Content preview from Tidy First? ―個人で実践する経験主義的ソフトウェア設計

2章デッドコード

 

消そう。以上。実行されないコードは消すだけだ。

デッドコードを消すことに強い抵抗を感じる人もいるだろう。誰かが時間と労力をかけて書き、それに対して組織がお金を払った。そんなコードが残っているのだ。無駄金にしないためには、またコードが呼び出されるようにすればよいだけだ。それに、消したコードが将来必要になったら、消したことを後悔するかもしれない。

このなかにどれだけの認知バイアスがあるか探してみてほしい。整頓好きなあなたへのエクササイズだ。

デッドコードを特定するのは簡単だ。だが、リフレクションが多用されているようなときには少し難しい。コードが使われていなさそうだと当たりをつけたら、整頓する前に使用状況のログを取ってみよう。本番環境に載せて、確信が持てるまで待つのだ。

「でも、もしあとで必要になったら?」と考えるだろう。そのためのバージョン管理なのだ。実際には何も削除していない。今は見る必要がないというだけだ。コードがもし(これは条件式の長い羅列だ)、1)たくさんある、かつ、2)今は使われていない、かつ、3)将来使いたい、かつ、4)書いた当初と同じ使い方をする、かつ、5)今も動作する、ならば、元に戻せる。そうでなければ、書き直したほうが良いものになる。しかし、最悪なことになったとしても、いつでも元に戻せる。

いつものように、少しずつコードを削除しながら整頓しよう。そうすれば、間違いに気づいても、比較的簡単に変更を元に戻せるだろう(28章参照)。「少しずつ」の尺度は認知的なものであって、コード行数ではない。条件式(たとえば真になることがわかっている場合)の節かもしれないし、ルーチン、ファイル、ディレクトリかもしれない。

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Tidy First?

Tidy First?

Kent Beck
Fluent React

Fluent React

Tejas Kumar
Command-Line Rust

Command-Line Rust

Ken Youens-Clark

Publisher Resources

ISBN: 9784814400911Publisher Website