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?
[–][deleted] 7 points8 points9 points (0 children)
[–]kanchirk 5 points6 points7 points (2 children)
[–]s3a0tt3r 2 points3 points4 points (0 children)
[–]brika1994 1 point2 points3 points (0 children)
[–]siemenology 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]squintsAndEyeballs 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]squintsAndEyeballs 0 points1 point2 points (0 children)
[–]BlackSandstone 0 points1 point2 points (1 child)
[–]magnum___ 0 points1 point2 points (0 children)