infoMore than 5 years have passed since last update.
考察 > 構造体メンバ変数へ値代入する場所
Last updated at Posted at 2016-10-03
- 多数の結果を格納するメンバ変数を持つ構造体があるとする
そのメンバ変数への結果の格納方法を検討してみた。
- 案1
- 様々なサブ関数の中で構造体のメンバ変数に代入をする
- 欠点: どこで値を代入したかソースリーディングしにくい
- 欠点: 代入漏れが発生する可能性あり
- 案2
- それぞれの計算結果を戻り値とする関数郡を用意する
- 1つのサブ関数において、
構造体のメンバ変数 = 対応関数()
という形のコール文を列挙する
- 利点: 代入している処理が見やすい
- 利点: 代入漏れの防止などしやすい
案1のような実装は「技術的負債」と思う。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
What you can do with signing up