DEV Community

loading...

Discussion on: No love for boolean parameters

Collapse
lukeshiru profile image
△ LUKE知る

I agree with you, but I wanted to also clarify that in React and similar component libraries, you have some properties that can be booleans because only have one of 2 states that can overlap (like open, disabled, and similar). What I mean is that we should favor not using booleans, but in some cases is the way to go.

Great article!

Collapse
tkdodo profile image
Dominik D Author

Definitely! I kinda omitted the fact that there are legit use-cases 😅, like if it's a boolean in a real-world scenario (enabled / disabled is a good example). I was more focussed on putting attention on wrong usages of booleans, because I think they outweigh the "real" booleans by a lot :)

see also the comment from @mcsee below: dev.to/mcsee/comment/1c1h8

Collapse
mcsee profile image
Maxi Contieri

in such cases you can use polymorphic decorators

It is a balance between hated booleans and over design

if you need to put just one IF, I guess booleans would be ok. if you have several ones you should favor using polymorphism as stated in Dominik's article