dimanche 5 avril 2015

Is it more clear to use !booleanVariable, or booleanVariable == false?


Vote count:

0




I'm unsure how it is done in the workplace. I've worked on two open source projects whereby the owner of one said to always do ! before booleans, because he said humans read it like "if not condition", whereby the variable is usually a true value from it's name (ex: isRed, livesForever, canEat...etc) therefore reading more like English (ex: He is not red).


On another project, the owner said he only wants to see == false because the ! is hard to see and your intention is more clear.


While both methods work and it can be a choice of preference, is there one that dominates in the workplace?


Is ! considered bad practice due to the chance a user may find it possibly harder to spot than == false?



asked 36 secs ago







Is it more clear to use !booleanVariable, or booleanVariable == false?

Aucun commentaire:

Enregistrer un commentaire