0
\$\begingroup\$

I think it would greatly help reviewers if we decide upon and adopt guidelines on readability oriented coding conventions. A few examples:

Blocks

One space between arguments, no new line braces

if( condition ) {
    // do this
} else {
    // do that
}

instead of

if(condition) 
{
    // do this
} 
else 
{
    // do that
}

No spaces after methods names

int funkyMethod(foo)

instead of

int funkyMethod (foo)

Proper identation

<html>
    <div id="funky">
        <p>Hello World</p>
    </div>
</html>

instead of

<html>
<div id="funky">
<p>Hello World</p>
</div>
</html>

I'm aware that such a proposal has high potential of turning into a flame war. I'm not suggesting we adopt the above examples, they are just examples, what I'm saying is that adopting common conventions is more important than what those are. Sensible conventions is the first step to any code review, providing them in the faq or in meta discussions as references will provide common ground for askers and editors

I'm in no way suggesting that we try to enforce our conventions to anyone, just providing a generic template for editors and experienced askers to format code in questions and answers. Such a guideline should be geared towards making code more readable first and smaller then. Small is good, since we have certain limitations at the amount of code that is shown in a code block at once.

Of course, same conventions will not apply to all languages. The python people especially will laugh out loud at our indentation peculiarities. But we could start with guidelines for C style languages, as the family is more popular.

As for how the adoption could work: We could brake suggestions into meta discussions and let people vote on which style they prefer.

Thoughts?

\$\endgroup\$
  • 3
    \$\begingroup\$ Why? I don't see what the point is in trying to come up a coding convention on a code review site. Sure following a convention is important, but I'm not seeing how having our own convetion would serve any purpose. \$\endgroup\$ – Winston Ewert Nov 14 '11 at 13:56
6
\$\begingroup\$

Where the poster has made some visible attempt at using an identifiable style, I usually prefer to retain that style, even if it's not my preferred style.

If the post has no discernible formatting "style" or indentation then I usually use what I (as the editor) am comfortable with for that particular language. (If the organisational body behind the language advocates one particular style then I would prefer that - but I am not aware of many languages where this is the case.)

Overall, I don't think we should force any one particular style, there are many opinions and and picking one over the others is just asking for trouble.

\$\endgroup\$
3
\$\begingroup\$

As a non-language specific coding convention for Code Review I would appreciate it if people reformat their code so that usage of the horizontal scrollbar is reduced to a minimum.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .