44

A co-worker posted a question and came back later to see that it had been edited.

TL;DR: a Java stacktrace was edited to wrap at 90 chars instead of scroll.

When we checked the edit my eyes glazed over; I would argue that the question has been made significantly less readable. I think the edit makes the question harder to understand, and therefore less likely to receive interest/answers.

Is there a rule that says code must be less than x chars on Stack Overflow? Or is this just some overzealous editing?

7
  • 7
    If the amount of code passed some limit, StackOverflow would not allow the question to be posted. If the OP doesn't like the edit, he can always rollback.
    – zondo
    Commented Jul 6, 2016 at 0:41
  • 20
    Actually, the editor turned the stack trace from a code block into a block-quote. I sort of see the logic, but agree that the stack trace was more readable as a code block, and so I have reverted the edit. Commented Jul 6, 2016 at 1:25
  • @RobertHarvey however, do we always have to use code block for error messages? In many cases block-quote is more handy. We discussed this yesterday with terdon in Ask Ubuntu and it doesn't seem to be a consensus.
    – fedorqui
    Commented Jul 7, 2016 at 10:50
  • 2
    @fedorqui: I usually use a block quote for short (i.e. under five lines) error messages, but a code block if it is longer. The block quote might have looked better than the code block if the line breaks were included. (double space at the end of each line), but adding all of those spaces doesn't seem to be worth it, especially when we consider that a block quote removes indentation and interprets markdown even when it is just part of the error message. With short messages, it may be that the block quote is nicer, but with long messages like this, I prefer a code block.
    – zondo
    Commented Jul 7, 2016 at 11:46
  • 4
    @zondo Given that it is essential that error messages get posted exactly as they were outputted the right formatting for them is using code blocks, in all cases. As you rightly mention quotes often do not show the same output as the console.
    – Bakuriu
    Commented Jul 7, 2016 at 19:26
  • 1
    @Bakuriu: I always use code blocks. My point is that it is not necessarily wrong to use a block quote. See my answer for details.
    – zondo
    Commented Jul 8, 2016 at 1:36
  • @zondo thanks for the insight both in comments and in your answer. Now it is pretty clear to me!
    – fedorqui
    Commented Jul 20, 2016 at 12:59

1 Answer 1

58

The editor probably thought that since it was not code, the closest thing is a quotation of the console. Therefore, change a code block to a block quote. Since it does not make the question easier to read, I would have rejected the edit had it come up in the review queue, and I might even rollback. (RobertHarvey♦ has now done this.) When I am in the editor's position, I usually just add

<!-- language: lang-none -->

just above the code block. That way, the stacktrace is displayed nicely and scrollably, but you don't get that weird syntax highlighting.


The question of code block or block quote is sometimes difficult with error messages. Since an error message is neither code nor a quotation, it doesn't really make sense to use either. What one must consider, however, is what makes the error display nicely? Block quotes may look nicer to some people, but there are some disadvantages. For each line break, either <br> or two spaces must be added or else the entire error message will be blotched together with line breaks that don't make sense. Then again, a block quote does not display the indentation that is common in error messages. Also, a block quote interprets those special characters that are used in markdown. Those characters might show some text as italic, for example, if there are two occurrences of * in the error message. With short messages that have no indentation and no special characters, I might be okay with a block quote:

ls: invalid option -- 'z'
Try 'ls --help' for more information.

With longer ones such as the one linked, that becomes impractical.

2
  • 10
    Hah, I just did that, before I saw your answer.
    – user1228
    Commented Jul 6, 2016 at 13:13
  • 2
    So a code block with language none is effectively a console output block. This may be exposed better to the user. Commented Jul 8, 2016 at 8:05

You must log in to answer this question.

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