Replies: 1 comment 2 replies
-
|
You're making a very valid point! I don't see the issue popping up so easily for enums since they are readily distinguishable by their unique syntax, but I completely agree with the issue you are lining out, especially for numerics and pointers. I think a 'mandatory verbosity' for those cases would be a sensible guideline! For bools (only) I would allow the brief notation as an acceptable notation - as you laid out, brevity is also a good thing if it does not create ambiguities or create potential issues! Thank you very much for bringing this up! |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Abstract
Propose to set more strict guidlines for boolean expressions, favoring verbosity to brevity with too compact boolean syntax.
Rationale
Ignoring functions that return complex objects that often provide their equality methods, many Qt functions return an enum which can be checked for equality. That is a great way to ensure the code both works and is readable.
However many more functions return a boolean that can be used with a very compact syntax when checking its
falsevalue. And as we know...That syntax lead me to an interesting predicament when checking if a pointer is null or not. I will exagerate the issue to prove my point.
if(!selected) { ... }In this experimental case what does
selectedmean? Selected or not, so bool? or the selected pointer is null? or perhaps selected represents the column so 0? Of course one can say that better naming likeselectedItemorisSelectedalleviates this issue but im inclined to not leave it up for interpretation.Details
The primary types that may lead to confusion are numerical values, bool and pointers when checked for their
0/false/nullptrvalues. The problem lies that one can make a brief expression which may end up causing confusion in the future.In order to be verbose these types should be explicitelly compared
Numeric
Bool
Enum
Pointers
Boolean Edge Case
The above guidelines can be altered for
boolso that, assuming they are strictly followed, can allow the briefif(!value)syntax exclusively for them. That way brevity is used conventionally only for them while numeric values stay explicit.Beta Was this translation helpful? Give feedback.
All reactions