Is there some rule when to use two functions or when to pass boolean parameter.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It has been a while since I last re-read Code Complete, but I vaguely recall McConnell addressing this, and the words “disjunctive conherence” pop into my head. Briefly,
versus
is often a choice, and depending on how similar or different
fwould behave undertrueversusfalse, it may make sense to break it into two functions and give them distinct names. Often a third choice is better, which is to change theboolto a two-value enum, where the enum name makes the distinction clear.The key is to look at the call-sites, and see if the meaning is clear just from reading the code. If you are tempted to put a comment on every boolean call-site:
and the call-sites usually call with boolean constants, that’s a strong smell that you should break it up into multiple functions.