Re: Deleting an element from a list in a loop

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Babak Pourat wrote:
Doug Harrison [MVP] wrote:
if ((*it)->ThreadFinished()) // Don't compare against true or false

Why ?

The point is this: If you use "some_result==true", this again yields a
boolean so in order to keep to your own standards, you would have to
write "(some_result==true)==true" and so on. Whenever you read something
like if(x), while(x) or for(..;x;..), you should know that x is a boolean
and how it is evaluated. Adding a redundant, explicit version of what is
done implicitly only clutters the code.

If, on the other hand, your code suffers in readability without the
comparison, you have a completely different problem. Adding a comparison
with 'true' doesn't really help then but at best work around this lack of
readability. In that case, you should rename some things so that the logic
becomes more apparent.

Uli

.



Relevant Pages

  • Re: reversing the comparison
    ... (Certainly doesn't have a d*mn thing to do with boolean returns etc. ... The only reason boolean returns came into it is because most modern languages force conditionals to only accept a statement that evaluates to a boolean - so the old constant == varialbe convention isn't a requirement.... ... compiler's static checking will issue a warning if you use an ... I didn't really believe in tight standards, until recently we farmed out some of our stuff to an india team.... ...
    (microsoft.public.vb.general.discussion)
  • Re: Avoiding Booleans & Danny Thorpe
    ... for readability if the enumerated constant isn't visibile. ... As in above, if you have a complex boolean statements, you ... Why not Pending and NotPending ... ENUMERATED TYPES AREN'T CLEAR EITHER ...
    (borland.public.delphi.non-technical)
  • Re: [PATCH] drivers/scsi/aic7xxx_old: Convert to generic boolean-values
    ... There's always an issue when two people work on the same driver ... ... I'm used to register layouts, and those are simple bitfields, so I don't ... It is a fundamental difference between an integer and a boolean. ... I don't quite see how this is relevant to the readability issue? ...
    (Linux-Kernel)
  • Re: Blocks for scope control
    ... boolean isValid(){... ... One can compare the readability of: ...
    (comp.lang.java.programmer)
  • Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
    ... So Ralf, if you are interested in readability and would like to remove ... a redundant test, then why not: ... If it's already boolean you don't need to check for "true". ...
    (borland.public.delphi.non-technical)