DEV Community

Discussion on: Tips on naming boolean variables - Cleaner Code

Collapse
 
dvddpl profile image
Davide de Paolis • Edited

absoulutely agree. i understand the need for the convention, since ( expecially at the beginning of your career) you are able to immediatly find or recogninze a boolean variable by the fact that starts with is or has, but was never bought into this.
exactly for the reason you mentioned,

is it a question? are you asking me? i don't know, you should tell me!

and because of the many exceptions that make some variables seriously grammatically terrible. I found this post because I was looking for alternatives or way of telling in a Pullrequest that isUserAlreadyExist is a complete NOPE for me...

imho, dimply use conventions when it makes sense, ( possiblly in thex affermative format - like useIsActive - which in my case would become a more natural userAlreadyExists)

Collapse
 
qodunpob profile image
Konstantin • Edited

What about the point that no code ask you but you have asked the data about something and store answer in variable with the same name?

Thread Thread
 
jamon_jamen_92fc34a24e45d profile image
Jamon Jamen

Then I already know the answer and can store it in a variable like userExists or saved. Don't need to ask once again. If I want to ask, I would use IsSaved() or IsExistingUser().

I especially love the pattern with some auto-generated codebase for based on OpenAPI or protobuf specs - the accessors Get prefix irritates me even more.
getIsActive() function always sounds to me as if by invoking this function I will get another function as a result, which will tell me if a user is active if I invoke it.

Collapse
 
aryzing profile image
Eduard Bardají Puig

isExistingUser