Slashdot Mirror


User: NeedleFactory

NeedleFactory's activity in the archive.

Stories
0
Comments
1
First seen
Last seen
Profile
(view on slashdot.org)

Comments · 1

  1. Coding Style Complete in Eight Rules on What Workplace Coding Practices Do You Use? · · Score: 1

    In July 1988 a colleague proposed a hefty set of programming style conventions for C. I objected to almost everything. He challenged me to propose conventions I could happily follow. I accepted the challenge, and came up with eight "Rules":

    Coding Style Complete in Eight Rules

    Clarity Rule
    Programs must be clear and easy to read.
    Wherever possible, clarity springs from the code itself;
    in other cases, including marginal cases, clarity requires supporting comments.
    Exceptions: None.

    Comment Rule
    Comments must provide (or reference) whatever information
    a competent programmer needs to grasp quickly the code's intent and method.
    Exceptions: None.

    One Page Statement Rule
    Every statement (including compound statements) must fit on a single page.
    Exceptions: None.

    One Page Function Rule
    Everyfunction definition must fit on a single page.
    Exceptions:
    1. Function header may occupy more than one page in furtherance of the Comment Rule.
    2. Other exceptions only if in furtherance of the Clarity Rule.

    Indentation Rule
    Statements at the same grain of resolution must have the same degree of indentation.
    Exception: Two or more consecutive statements may occupy a single line,
    if in furtherance of the Clarity Rule.

    Compund Statement Rule
    When a compund statement occupies more than one text line, all
    subordinate statements must be indented with respect to their parent statement.
    Exceptions: None.

    Long Statement Rule
    When a statement extends over more than one text line, each continuation line must be indented w.r.t. the first line, and line breaks must partition the statement harmoniously.
    Exceptions: Permitted only in furtherance of the Clarity Rule.
    Example: If the second line of a compound C or C++ statement begins with one of the brace characters ("{") enclosing the subordinate statements, then this line may have the same indentation as the first line if you think clarity is served thereby.

    Interchange Conventions
    Certain conventions facilitate sharing code both on screen and on paper:
    1. Both ends of lines are visible under normal conditions. (80 character max suggested.)
    2. A page must fit on a standard printer page. (60 lines max suggested)
    3. Pages are delimited by form feeds.
    4. Tab stops should be uniform. (3 spaces per tab is suggested.)
    Exceptions: None.