Every day I leave comments on the site asking users to fix their code formatting, or notes that I have already done so. True, a lot of it comes down to apathy (or lack of consideration) on the part of askers, but after some examination I have come up with several ways that the process can be smoothed out. My goal here is to reduce the amount of accidental errors in posting code, and/or misunderstandings of how the formatting works.
I have lost count of the number of times I have seen stray
enter code here
text in questions. The problem has been known about for a long time. I propose a different solution: instead of trying to detect when this happens, just don't add the text, under any circumstances. Instead, position the caret after adding text to the post. The "enter code here" text is not helpful UI-wise, because the user just finished consciously choosing the option.Indented code blocks are awful. They are inferior to code fences in almost every conceivable way: they don't allow for specifying a language; they don't neatly delineate the code; they require blank lines before and after the block (and this is not explained either on the post form or in the formatting help); and they require extra space to be added in front of each line of the block (which is to say, they are much harder to do manually, and are the source of ungodly amounts of python questions with misindented code); and they need an extra hack to work with numbered or bulleted lists (this is explained on the form if you recognize the help menu, which is not at all obviously recognizable as a help menu; it is not explained in the formatting help.)
The "each line" problem is especially bad because if you have an indented line of code and hit return, the next line is not auto-indented (as typical IDEs would do). So if you don't have code to paste, you're slowed down when typing it in manually.
Worse yet, code blocks make a lot of real-world code look almost right (because the bulk of the code is indented at least one level, and four spaces is a commonly used indent), making it harder for OP to realize the mistake, and making it harder for answerers to notice that the original code does, in fact, have the appropriate import
s etc.
The system should use fences when the button is clicked, and labelling the current behaviour as "by design" is absurd. It's even worse because the {}
button can't even be consistently used as an "indent" button - if all the selected lines are indented, it will dedent instead. This is a misfeature because 1) it is inconsistent and 2) there is already an undo function.
Oh, and if code fences are used, clicking the button on a blank line with no text selected allows for just adding the fences. With a code block, you have to indent four spaces, and then either not leave a printable character as evidence, or (as actually happens) write the dreaded enter code here
text.
- There are many common patterns of failure that could be automatically detected. One is attempting to use an inline code span for each line of code:
def like_this():
# and this
# and this
Another is trying to paste an entire multi-line code as an inline block:
def like_this(): # and this # and this
Another is trying to put code fences on the same line of the code (check the source for the post; notice how this type of error hides actual code completely, and breaks the rest of the post):
# and this
# and this```
All of these could be detected by regex, and the latter two could be mitigated by checking what is on either side of the caret when text is pasted into the form.
>
for that).Ctrl-K
away the indent instead of copy-pasting the code into an off-site editor is a godsend. Otherwise, I'm fully in support of replacing the indent behavior of the current editor. Worth noting that the new editor (despite its own horrors) does use fence notation.