More than 5 years have passed since last update.
第7章 制御フローを読みやすくする
比較の条件を書くときは、変化する値を左、より安定した値を右に配置する
例 if(hoge < 15)
if/elseブロックは 肯定形、単純、目立つものを先に処理する
三項演算子、do/whileループ、goto文などはコードが読みにくくなるため、別の方法で記述する
ネストが深いとコードを追うのに集中力が必要になるため、できるだけ深くしない
深いネストを避けるためには、処理結果が確定したら早めに処理を抜けることで実現できる。
所感
数か月前、ソースコードレビューを受けた際に「処理結果が確定したら早めに処理を抜ける」ことを指摘されたことを思い出した。
このようなルールをプロジェクト内で規約として記載しておくと、ソースコードの質が平均化できると感じる。
Why not register and get more from Qiita?
- We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
- you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
Sign upLogin