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.
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 :)
Learn something new every day.
- I am a senior software engineer working in industry, teaching and writing on software design, SOLID principles, DDD and TDD.
Location
Buenos Aires
Education
Computer Science Degree at Universidad de Buenos Aires
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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!
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
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