Skip to Content
ロバストPython ―クリーンで保守しやすいコードを書く
book

ロバストPython ―クリーンで保守しやすいコードを書く

by Patrick Viafore, 鈴木 駿, 長尾 高弘
March 2023
Intermediate to advanced
384 pages
5h 30m
Japanese
O'Reilly Japan, Inc.
Content preview from ロバストPython ―クリーンで保守しやすいコードを書く

11章インタフェースの定義

前章ではユーザ定義型の作り方を学んだが、作っただけで道のりはまだ半ばだ。他の開発者はあなたのデータ型を実際に使わなければならない。彼らはそのためにデータ型のAPIを使う。APIとは、他の開発者がコードを使うために実際に操作するデータ型と関連する関数(外部にある関数を含む)を集めたものである。

利用者の前にあなたが定義したデータ型を差し出すと、そのデータ型は想像もつかなかったような方法で利用、誤用、悪用される。そして、彼らがあなたのデータ型に依存するコードを書き出すと彼らの行動を変えるのは難しくなる。すると、私がコードインタフェースのパラドックスと呼ぶものが起きる。

インタフェースを正す機会は1度しかないのに、実際に使われるまでインタフェースが正しいかどうかはわからない。

開発者たちはあなたが作ったデータ型を使い始めた途端、データ型の振る舞いに依存する。後方互換性のない変更を加えるとすべての呼び出し元のコードが動作しなくなる可能性がある。インタフェースの変更が抱えるリスクはそれに依存する外部コードの数に比例する。

定義したデータ型に依存するコードがすべてあなたの管理下にある場合はこのパラドックスは起きない。インタフェースを変更できる。しかし、そのデータ型が本番稼働に移ると同時に人々はそれを使い始め、データ型は変更しづらくなる。ロバストネスと保守性が重要な意味を持つ大規模なコードベースでは、全面的な変更を加えるために必要な承認の手続きにコストがかかる。また、オープンソースライブラリやプラットフォームSDKなど社内で管理できないものに含まれるデータ型に対しては変更がほぼ不可能だ。そのため、扱いにくいコードが簡単に生まれ、開発者の作業を遅らせることになる。

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

Pythonからはじめるアルゴリズムトレード ―自動売買の基礎と機械学習の本格導入に向けたPythonプログラミング

Pythonからはじめるアルゴリズムトレード ―自動売買の基礎と機械学習の本格導入に向けたPythonプログラミング

Yves Hilpisch, 村上 振一郎
サイトリライアビリティワークブック ―SREの実践方法

サイトリライアビリティワークブック ―SREの実践方法

Betsy Beyer, Niall Richard Murphy, David K. Rensin, Kent Kawahara, Stephen Thorne, 澤田 武男, 関根 達夫, 細川 一茂, 矢吹 大輔, 玉川 竜司
スクラム実践者が知るべき97のこと

スクラム実践者が知るべき97のこと

Gunther Verheyen, 吉羽 龍太郎, 原田 騎郎, 永瀬 美穂

Publisher Resources

ISBN: 9784814400171Other