3

Disclaimer: For languages where the indent is not part of the syntax (e.g. C++).

Scenario: a question with a very poorly formatted code. The error is related to — let’s say — wrongly closed (or not closed braces), but the error message doesn’t make this clear. The cause of the error is buried in a very very bad formatted code. Properly formatting the code in the question would reveal the cause of the problem (in a doh! moment).

So should the code in the question be formatted, or should the format be considered a part of the problem and dealt with it exclusively in an answer?

I don’t have an example right now, but I remember 2 or 3 such cases a while back.

2
  • I wouldn't say it's correct to assume, considering all the issues some users have posting code, the format is the same as on their machine. It's possible they've actually missed the error. Commented Aug 7, 2014 at 10:24
  • 1
    @ChiefTwoPencils well, not rly, when you see }}}}} on the same line, I would say it’s the same on their machine.
    – bolov
    Commented Aug 7, 2014 at 10:51

1 Answer 1

4

This is one of the reasons editing code in questions is very problematic and has to be done with great care (if it's done at all).

The problem might be in the code as posted or it could be that the OP has mangled the code when entering into the question. Your first action should probably be to comment. Point out the syntax error and ask if this is the actual code or an edited version. I realise that in the case you describe it would appear to be the former case - but you can't always assume that.

In the first case this gets the OP their answer and you can covert the comment into an answer.

In the second case you hopefully get the OP to clarify the question and post the actual code at which point you can answer the actual problem.

4
  • so… don’t format the code (at least not right away) is what you are saying.
    – bolov
    Commented Aug 7, 2014 at 10:57
  • 1
    @bolov - The only code formatting you should consider is making sure that each line starts with 4 spaces so that it get's highlighted as code. Don't do anything else.
    – ChrisF Mod
    Commented Aug 7, 2014 at 11:02
  • I' mainly active in the mysql tag. I see regularly SQL statements in just one line. Often I break these statements so that horizontally scrolling will be avoided. Would you recommend not to do edits like this? Same goes for so much empty lines in code, so you've got to scroll vertically.
    – VMai
    Commented Aug 7, 2014 at 13:38
  • This is such an example of yesterday
    – VMai
    Commented Aug 7, 2014 at 13:44

You must log in to answer this question.

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