<story><title>Named Booleans prevent C++ bugs and save you time</title><url>https://raymii.org/s/blog/Named_Booleans_prevent_bugs.html</url></story><parent_chain><item><author>Animats</author><text>The only problem with this approach is that you evaluate all the conditions, even if you don&amp;#x27;t need to. Sometimes that&amp;#x27;s inefficient, and sometimes it&amp;#x27;s invalid, as in&lt;p&gt;&lt;pre&gt;&lt;code&gt;    char *p = NULL;
    ...
    if (p &amp;amp;&amp;amp; *p != &amp;#x27; &amp;#x27;) { ... }
&lt;/code&gt;&lt;/pre&gt;
If you write&lt;p&gt;&lt;pre&gt;&lt;code&gt;    bool p_non_null = (p != NULL);
    bool char_non_space = (*p != &amp;#x27; &amp;#x27;);
    if p_non_null &amp;amp;&amp;amp; char_ non_space { ... }
&lt;/code&gt;&lt;/pre&gt;
Oops.</text></item></parent_chain><comment><author>wruza</author><text>Back in mid-00s I was thinking about languages and features. One of the keywords I still miss in mainstream is “alias”. Alias is a symbol that only evaluates lazily.&lt;p&gt;&lt;pre&gt;&lt;code&gt;  alias not_null = (bool)p;
  alias not_space = (*p != &amp;#x27; &amp;#x27;);

  if (not_null &amp;amp;&amp;amp; not_space) {
&lt;/code&gt;&lt;/pre&gt;
This may bite you in another way, but living in a world where everything gets evaluated asap-y isn’t syntactically easy either.&lt;p&gt;Would be also nice to have this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  alias __cache foo = &amp;lt;heavy(expr())&amp;gt;;

  if (foo &amp;amp;&amp;amp; foo.length &amp;amp;&amp;amp; foo[0].x) {
&lt;/code&gt;&lt;/pre&gt;
`foo` only evaluates once.</text></comment>
<story><title>Named Booleans prevent C++ bugs and save you time</title><url>https://raymii.org/s/blog/Named_Booleans_prevent_bugs.html</url></story><parent_chain><item><author>Animats</author><text>The only problem with this approach is that you evaluate all the conditions, even if you don&amp;#x27;t need to. Sometimes that&amp;#x27;s inefficient, and sometimes it&amp;#x27;s invalid, as in&lt;p&gt;&lt;pre&gt;&lt;code&gt;    char *p = NULL;
    ...
    if (p &amp;amp;&amp;amp; *p != &amp;#x27; &amp;#x27;) { ... }
&lt;/code&gt;&lt;/pre&gt;
If you write&lt;p&gt;&lt;pre&gt;&lt;code&gt;    bool p_non_null = (p != NULL);
    bool char_non_space = (*p != &amp;#x27; &amp;#x27;);
    if p_non_null &amp;amp;&amp;amp; char_ non_space { ... }
&lt;/code&gt;&lt;/pre&gt;
Oops.</text></item></parent_chain><comment><author>bandika</author><text>The correct rewriting would be:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    bool char_non_space = p_non_null &amp;amp;&amp;amp; (*p != &amp;#x27; &amp;#x27;);&lt;/code&gt;&lt;/pre&gt;</text></comment>