Guidance for beginners and experts on how to set up a Windows driver developm...Atomu Hidaka
?
This explains how to build a Windows driver development environment that can be used immediately by beginners and experts alike. The author, who has extensive experience developing various Windows drivers, shows the latest and simplest ways to use Visual Studio and WDK.
26. 9. 静的解析可能な分岐網羅を使う
PHP 8.0 で入ったmatch は分岐網羅
検査がある
想定してない値が来ると例外
Psalm はdefault のないmatch や
switch で静的に分岐網羅を検査でき
る場合がある
値のUnion やEnum をうまく使う
無闇に可変関数呼び出しなどの動的
処理は使わない、愚直に分岐を書く
enum Result {
case Succeed;
case Failed;
}
// ResultStatus::Failed を網羅してないの
// 静的解析段階でエラーになる
function f(Result $status): int {
return match ($status) {
ResultStatus::Succeed => 1,
};
}
27. 10. 書き込み、状態を減らす
PHP 8.1 でreadonly が追加
Psalm でも@immutable や@pure
などがある
なるべく完全コンストラクタ+不変
状態を持たない= 各生成時点で全情
報が必要
小さなクラスが増え神クラス化
も防ぎやすくなる
class ReadOnlyClass
{
public function __construct(
public readonly int $id,
public readonly string $name,
) {
}
}
/** @psalm-immutable */
class ImmutableClass
{
public function __construct(
public int $id,
public string $name,
) {
}
}
28. 11. なるべく多くを型で表現
ValueObject 、DTO みたいなのをバ
ンバン作る
ID の種類ごとに異なるクラスを定
義する
ジェネリクスを使ってもよい
実クラスを定義しなくとも型
タグを使える
ちかぢか同僚が会社のブロ
グで紹介するかも
trait ItemId {
public function __construct(
public readonly int $value,
) {
}
}
class ConsumableItemId {use ItemId;}
class EquipmentItemId {use ItemId;}
class Consumableuser {
public function useItem(
ConsumableItemId $item_id
): void {
}
}