Page List

Search on the blog

2018年12月23日日曜日

reason about computer programs

 以前「Functional Programming in Scala」という本を読んでいたときに「reason about」という表現が出てきた。そのときはしっくりとくる和訳を見つけられずにいた。

Because of their modularity, pure functions are easier to test, to reuse, to parallelize, to generalize, and to reason about.

The use of throw and catch means we can no longer reason about our program purely locally by substituting terms with their definitions.

 どうやら純粋関数でプログラムを書くと reason abount しやすいらしい。最近読み出した「AN INTRODUCTION TO PROGRAMMING IN GO」という本でも同じ表現が出てきた。

You'll spend a large amount of your time just trying to fix your program so that it finally compiles. But types help us reason about what our program is doing and catch a wide variety of common mistakes.

 改めて辞書を引いてみると、「〜について論理的に考える、判断する」というのが妥当な和訳っぽい。そういえば日本語でも、ものごとについて論理的に考えて推論することをリーズニングというなぁ。

 ということで、reason about program でググっていたら面白い記事を見つけた。

 reason about という表現はバズワード的に使われるが、実は重要な意味がある。リーズニングしやすいコードとは以下の特性を持っている。
  1. 意図しない副作用を持たないこと
  2. 外部の状態に依存・影響しないこと
  3. 参照透明性
上記の特性を保証するには様々な方法がある。
  1. ユニットテスト
  2.  型
  3. イミュータビリティ
ユニットテストはコードが正しく動くことを保証してくれるしドキュメントとしても利用できるが徹底的に考えないとエッジケースを取りこぼしてしまう。型・イミュータビリティはコードに制約を課すが様々なエッジケースを防いでくれる。