Boolean arguments loudly declare that the function does more than one thing. They are confusing and should be eliminated.
Hello all.IntroductionI've recently finished reading Clean Code (excellent btw) within the last 3 months.I have been maniacally evangelizing to my peers at work every since. The atmosphere that our company's owner has created for us is phenomenal. I can't speak highly enough about it. Our owner is a highly skilled developer in his own right, and as such, is firmly focused on maintaining an environment where the devs can be most successful. We follow the Agile principles and we want to be the best developers in the world.I've started applying the lessons learned from the book in my current project. However, none of the other devs are on board with this process (because they haven't yet had a chance to read the material. Most of them are still reading Code Complete and plan to read Clean Code next). Everyone readily agreed that functions should only do one thing, so I figured the first thing I should start cleaning is our functions.During the code reviews, I have to defend my choices. I thoroughly enjoy this process, because as you said in Clean Coder, it gives me an opportunity to teach.The ProblemRecently, the team has expressed that it doesn't agree that passing a Boolean to a function should be avoided. I explained that it automatically implies that the method is doing more than one thing: one thing when the value is true and a different thing when the value is false. Yet they insist that the code to accommodate that guideline is bloated and much harder to follow. And they say things like "so you would really resort to Template Method just so you don't have to pass in a bool? That's making the code more complex, not less". To which I don't have a good reply.My QuestionSo can you please explain this concept in more detail, or point me to a source where this is explained in more depth? I would really appreciate this.Thanks!
function var_dump(mixed $variable, $return = false) {}
function print_r(mixed $variable, $return = false) {}
function sprint_r($variable) {
return print_r($vaiable, true);
}
function svar_dump($variable) {
return var_dump($variable, true);
}
Hello all.IntroductionI've recently finished reading Clean Code (excellent btw) within the last 3 months.I have been maniacally evangelizing to my peers at work every since. The atmosphere that our company's owner has created for us is phenomenal. I can't speak highly enough about it. Our owner is a highly skilled developer in his own right, and as such, is firmly focused on maintaining an environment where the devs can be most successful. We follow the Agile principles and we want to be the best developers in the world.I've started applying the lessons learned from the book in my current project. However, none of the other devs are on board with this process (because they haven't yet had a chance to read the material. Most of them are still reading Code Complete and plan to read Clean Code next). Everyone readily agreed that functions should only do one thing, so I figured the first thing I should start cleaning is our functions.During the code reviews, I have to defend my choices. I thoroughly enjoy this process, because as you said in Clean Coder, it gives me an opportunity to teach.The ProblemRecently, the team has expressed that it doesn't agree that passing a Boolean to a function should be avoided. I explained that it automatically implies that the method is doing more than one thing: one thing when the value is true and a different thing when the value is false. Yet they insist that the code to accommodate that guideline is bloated and much harder to follow. And they say things like "so you would really resort to Template Method just so you don't have to pass in a bool? That's making the code more complex, not less". To which I don't have a good reply.My QuestionSo can you please explain this concept in more detail, or point me to a source where this is explained in more depth? I would really appreciate this.Thanks!
Hello all.IntroductionI've recently finished reading Clean Code (excellent btw) within the last 3 months.I have been maniacally evangelizing to my peers at work every since. The atmosphere that our company's owner has created for us is phenomenal. I can't speak highly enough about it. Our owner is a highly skilled developer in his own right, and as such, is firmly focused on maintaining an environment where the devs can be most successful. We follow the Agile principles and we want to be the best developers in the world.I've started applying the lessons learned from the book in my current project. However, none of the other devs are on board with this process (because they haven't yet had a chance to read the material. Most of them are still reading Code Complete and plan to read Clean Code next). Everyone readily agreed that functions should only do one thing, so I figured the first thing I should start cleaning is our functions.During the code reviews, I have to defend my choices. I thoroughly enjoy this process, because as you said in Clean Coder, it gives me an opportunity to teach.The ProblemRecently, the team has expressed that it doesn't agree that passing a Boolean to a function should be avoided. I explained that it automatically implies that the method is doing more than one thing: one thing when the value is true and a different thing when the value is false. Yet they insist that the code to accommodate that guideline is bloated and much harder to follow. And they say things like "so you would really resort to Template Method just so you don't have to pass in a bool? That's making the code more complex, not less". To which I don't have a good reply.My QuestionSo can you please explain this concept in more detail, or point me to a source where this is explained in more depth? I would really appreciate this.Thanks!