Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Code Complete is a commonly recommended book that goes into some detail about those kinds of stylistic issues. Also consider taking a look at some of the published organization style guides to see if they have any opinions on the issue; <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml" rel="nofollow noreferrer" title="Google&#39;s Style Guide">Google's Style Guide</a>, for instance.</p> <p>As to what I prefer, the second example is much better to my mind. The first is essentially an abuse of the do {} while construct to avoid using a goto, dogmatically sticking to the letter of "avoid gotos at all cost" while missing its spirit of "code for clarity, don't use unobvious language tricks". </p> <p>In fact, the only reason to even use a goto at all would be to dogmatically stick to a "only one return statement per function" approach when you could get away with a simple, readable</p> <pre><code>if (!isAdmin()){ return false; } else if (!isConditionOne()){ return false; } else if (!isConditionTwo()){ return false; } else if (!isConditionThree()){ return false; } else return generateReport(); </code></pre> <p>Other thoughts?</p> <p>Don't name local variables that are used to hold a computed success state "returnValue" or similar. <em>Obviously</em> whatever you return is the return value, any one who can read C can see what is being returned. Tell me <em>what</em> computation it holds. The name "returnValue" gives me no information as to what it means when it is true or false. In this example "couldGenerateReports" or similar would be far more preferable.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload