Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boolean parameters in methods. Why not?

I'm using reek as an analyzing tool for best practices in my code. However recently I found that if in the method, I have boolean parameters, such as.

def method (flag = true)

reek gives me a warning. Why does reek tell me that it is a warning?

like image 737
Jackie Chan Avatar asked Feb 24 '12 05:02

Jackie Chan


1 Answers

A couple of years before I wrote reek I blogged about this code smell here: http://silkandspinach.net/2004/07/15/avoid-boolean-parameters/

The problems with Boolean parameters all have to do with duplication and the SRP: the called method has two responsibilities, and the caller knows which one it wants to invoke.

like image 186
kevinrutherford Avatar answered Sep 22 '22 03:09

kevinrutherford