Rokiのチラ裏

学生による学習のログ

P0707R1 Metaclasses の Design principles

P0707R1 は メタクラスという新しい概念、言語機能についての提案論文である。論文の中身そのものとは少し離れるのだが、1.1 の Design principles が中々良いデザイン原則で他のものにも流用できるな〜と感じたので引用してメモ。

The primary design goal is conceptual integrity [Brooks 1975], which means that the design is coherent and reliably does what the user expects it to do. Conceptual integrity’s major supporting principles are:
  • Be consistent: Don’t make similar things different, including in spelling, behavior, or capability. Don’t make different things appear similar when they have different behavior or capability. – For example, in metaclasses we use normal class declaration syntax instead of inventing novel syntax.
  • Be orthogonal: Avoid arbitrary coupling. Let features be used freely in combination. – For example, in these papers for can be used to process a reflected collection of items (e.g., all the member functions of a class), without having a distinct special-purpose for_each<> on a reflected collection.
  • Be general: Don’t restrict what is inherent. Don’t arbitrarily restrict a complete set of uses. Avoid special cases and partial features. – For example, this paper prefers to avoid creating a special-purpose syntax to declare metaclasses, and instead lets programmers write metaclasses using normal class scope declaration syntax plus the general features of reflection and compile-time programming. Also, metaclasses are just code, that can appear wherever code can appear – written inside namespaces to avoid name collisions (including putting common ones in std::), and shared via #include headers or via modules.
  • These also help satisfy the principles of least surprise and of including only what is essential, and result in features that are additive and so directly minimize concept count (and therefore also redundancy and clutter).

主な設計目標は概念的な完全性である[Brooks 1975]。これは、設計に一貫性があり、ユーザーが期待することを確実に実行することを意味する。概念的完全性の主要な支援原則は

  • 一貫性を保つ:綴り、動作、能力など、似たようなもの同士のそれを変えない。異なる行動や能力を持っているときに、異なるものが似ているように見せない。例えば、メタクラスでは、新しい構文を発明するのではなく、通常のクラス宣言構文を使用する。
  • 直交させる:任意の結合を避ける。機能を自由に組み合わせて使用​​できるようにする。 - 例えば、これらの論文では、リフレクションされたコレクションに対して別個の特別な for_each<>を持たずに、コレクション(例えば、クラスのすべてのメンバー機能)を処理するために使用する事ができる。
  • 一般的にする:固有のものに制限しない。特殊なケースや部分的な機能を避ける。例えば、この論文では、メタクラスを宣言するための特別な構文を作成することを避け、通常のクラススコープ宣言構文とリフレクションとコンパイル時のプログラミングの一般的な機能を使用してプログラマーメタクラスを書き込ませるようにしている。また、メタクラスは名前の衝突を避けるためにstd::名前空間に共通のものを入れたり、#includeヘッダやモジュールを介して共有するなどをしている。