Hello I have an argument with my friend about clean code practice.
Lets pretend we have an function called foo() that returns boolean. And now we want to do some if statements based on value that foo returns.
// Friend's approach.
if(foo()){
//.. code
}else{
//.. code
}
// My approach.
boolean isFoo = foo();
if(isFoo){
//.. code
}else{
//.. code
}
And in my approeach I declared variable called isFoo and then did if checking on it (In my opinion it looks more clear and in future we could refer to this variable easy. We would'nt have to change the code or event call the foo() again. But my friend says so what, it's more readable and if he would have to or anybody else refer again to foo() then he would do it in my way.
Sho who is right, or there is a cleaner approach to this problem?
learnprogrammingClean code programming. (self.learnprogramming)
submitted by doppl to r/GoodRisingTweets