私たちは通常、失敗を避けるためにビジネス ロジックに不必要なチェックを入れます。
例えば。
1. public ObjectABC funcABC(){
ObjectABC obj = new ObjectABC;
..........
..........
//its never set to null here.
..........
return obj;
}
ObjectABC o = funABC();
if(o!=null){
//do something
}
null になることはないと確信しているのに、なぜこの null チェックが必要なのでしょうか? それは良い習慣ですか?
2. int pplReached = funA(..,..,..);
int totalPpl = funB(..,..,..);
funA() just puts a few more restriction over result of funB().
Double percentage = (totalPpl==0||totalPpl<pplReached) ? 0.0 : pplReached/totalPpl;
チェックは必要'totalPpl<pplReached'
ですか?
問題は、そのようなチェックを行うことで、根本的な問題を飲み込んでいないかということです。これらのチェックを入れることで、理想的に表示されるべき問題が回避されます。
おすすめの方法は?