aksel / DevCalc

Software developer's calculator, for Android
1 stars 0 forks source link

Convert mInput from Integer to int #4

Closed veyndan closed 8 years ago

veyndan commented 8 years ago

The use of null on mInput is unnecessary as conditional statements checked for both mInput being null or 0. Also when mInput is found to be null, it is commonly set to 0 anyway. Using the primitive instead of the primitives wrapper class improves readability and reduces the potential for bugs, due to the inability of primitives to be set to null.

aksel commented 8 years ago

You are correct.

Originally, I used null to check if any input had been received. In setOperator, it shouldn't calculate the operation if no input had been received, but change the operator instead. But what if the user inputs 0? Primitives can't be null. And 0 is valid input. So I used Integer.

There was only one state where mInput was null, and that was immediately after setting the operator. But that isn't used any more, because I seem to have added mInput == 0 to the if clause at line 279. So the null is indeed useless.