6
\$\begingroup\$

I've been thinking recently that Code Review might encapsulate Code Presentation style, such as:

  • Helpful comments and documentation.
  • Indentation/bracketing style.
  • Overall code structure.

Of course, I realise that this can be downright subjective. For instance, there's always this little thing that people disagree on:

Something {
    thing;
    other;
}

Or:

Something
{
    thing;
    other;
}

Or even

Something
{ thing
; other
;}

These issues aside, would it be acceptable to post a question such as "How can I make this code look tidier?" on Code Review? If so, with what restrictions, and if not, why?

\$\endgroup\$
11
\$\begingroup\$

Yes, you can. With some gotchas:

Do not post example code

This is a big subject that is covered well in our meta post about Why is hypothetical code off-topic for Code Review?

Avoid A vs. B questions

Decide on the formatting you like the most first, then ask for feedback about it.

Posting two versions of your code may get closed as "primarily opinion-based". There are some things which are just... holy wars... that programmers never agree about (for example spaces vs. tabs and Egyptian-style vs C#-style braces)

\$\endgroup\$
  • 4
    \$\begingroup\$ Pfft. Everyone knows you just let the IDE turn tabs into spaces. Holy war ended. Braces on the other hand... Well now... \$\endgroup\$ – RubberDuck Jul 21 '15 at 22:09
9
\$\begingroup\$

Assuming that the question is about a programming language that has no official style guide, if a question is purely about whitespace, I would likely move to close it as Primarily Opinion Based. I would view such a question as a skirmish in the never-ending Brace Wars. Such discussions are rarely conclusive or productive.

If phrased in a sufficiently open-ended way, though, the question could work. The following factors could swing the decision in your favour:

  • Instead of asking point-blank about formatting choices A, B, or C (what we call a ), just post one version of it and mention your concern about the problematic lines.
  • Include sufficient surrounding code and background information about what the code aims to achieve, so that reviewers have latitude to rewrite the smelly code altogether.
\$\endgroup\$
5
\$\begingroup\$

You can already do this: in this site, you can say something like this:

How can I make my code look neater?

Or something along those lines.

\$\endgroup\$
2
\$\begingroup\$

If you were writing something in Python and you wanted to know if you were following code standards, you would say something like "is my code Pythonic enough" or something to that effect.

other terms are

  • DRY -> Don't Repeat Yourself
  • Clean
  • Neat
  • Idiomatic

If you hang around long enough you will pick up some nice terms for talking about writing code that explains itself and is easy to read.

\$\endgroup\$

You must log in to answer this question.

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