A defense for bracket-less code

Don Taylor nospamformeSVP at gmail.com
Wed Apr 26 10:20:57 EDT 2006


Found in a style guide (http://www.artlogic.com/careers/styleguide.html)
-----------------------------------------------------------------------
Another case where "unnecessary" braces should be used is when writing 
an empty while loop:

while (*p++ = *q++)
{
    // this loop intentionally left empty...
}

instead of the form that is more commonly found:

while (*p++ = *q++);

By prohibiting this common loop format, we can easily check for cases 
where legal (but wrong) code like:

int i = 0;
while (i++ < kLoopLimit);
{
    myBuffer[i] = 0;
}

performs a loop with no body, then executes the intended body of the 
loop exactly once. Python programmers can stop chuckling now.
-----------------------------------------------------------------------

Don.




More information about the Python-list mailing list