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? ―個人で実践する経験主義的ソフトウェア設計

3章シンメトリーを揃える

 

コードは有機的に成長する。「有機的」という言葉を軽蔑の意味で使う人もいるが、私にはわからない。将来必要となるすべてのコードを一度に書くことはできない。それができるのは、私たちが何も学ばなかったときだけだ。

有機的に成長するなかで、同じ問題であっても、取り組む時期や人が違えば別の形で解決されることがある。それは構わないが、読むのが難しくなる。読み手としては、一貫性が欲しい。パターンが見つかれば、起きていることを理解しながら、安心して結論までジャンプできる。

変数の遅延初期化の例を見てみよう。違う方法で書いてあるのがわかる。

foo()
    return foo if foo not nil
    foo := ...
    return foo

foo()
    if foo is nil
        foo := ...
    return foo

# トリッキー
foo()
    return foo not nil
        ? foo
        : foo := ...

# 代入が式であると仮定すると、二重でトリッキー
foo()
    return foo := foo not nil
        ? foo
        : ...

# 条件が隠されていて、もっとトリッキー
foo()
    return foo := foo || ...

もっと別の形を発見、発明できるか考えてみよう。

どれも「まだ値が決まっていないfooの値を計算してキャッシュする」方法だ。どの方法にも善し悪しがある。読み手はどの方法でもすぐに慣れるだろう。混乱が起きるのは、2つ以上のパターンが同じように使われる場合だ。読み手は、違いは違いであることを期待する。違いは、同じことをしているという事実を覆い隠すのだ。

やり方を1つ選ぼう。他もそのやり方に合わせよう。不要なバリエーションを1つずつ整頓していこう。たとえば最初に遅延初期化に取り組んでみるのはどうだろう。 ...

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