[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] Safer is the Yoda style?
From: |
Greg Chicares |
Subject: |
Re: [lmi] Safer is the Yoda style? |
Date: |
Mon, 10 Jun 2019 16:50:52 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 |
On 2019-06-10 12:07, Vadim Zeitlin wrote:
> On Sun, 9 Jun 2019 21:17:24 +0000 Greg Chicares <address@hidden> wrote:
>
> GC> When writing an assertion, I experimentally deviated from the "Yoda"
> GC> style, to see whether gcc would flag the error. It didn't.
[...because it was an assertion macro implemented as 'if(!(condition))'...]
> And, for completeness, I also checked if wxASSERT() also suffers from the
> same problem and, unfortunately, it does. This is even stranger, however,
> as it doesn't add extra parentheses and uses "!(expr)" in its expansion
> instead -- and it turns out that this is enough to disable -Wparentheses
> from both gcc and clag too (while MSVC still gives it in this case too).
> So at the very least, I'm going to apply this change:
>
> https://github.com/wxWidgets/wxWidgets/pull/1345/commits/04435144ac9f27c7958398177741b796987f0daa
I just committed a similar change in lmi.
> The conclusion I'd like to draw from this is that we shouldn't be using
> assert() and modify LMI_ASSERT() in the same way I've modified wxASSERT()
> above, i.e. use direct condition instead of its negation.
>
> Would you agree with that?
I did modify LMI_ASSERT, and I don't use the C assert macro in real code.
I'll continue using the "Yoda" style, though. In the code I was writing
yesterday, it saved me from an awful mistake. If a native speaker of APL
you were, dislike it you would not.