By far the most common and frustrating issue I have with new users on SO is their almost complete ignorance of code-formatting conventions. Is there some way to either better educate new users and/or make it less tiresome for experienced users to improve the formatting?

Here are some ideas in this vein:

  1. Vote to quarantine a question (prevent answers) until the user fixes some nominated problem.
  2. Add an in-line code formatting facility. Without going into edit mode, select the text that should have been formatted as code and press Ctrl+K.
  3. Auto-detect probable code blocks and warn the user before accepting their question.

3 Answers 3



Simple method for reliably detecting code in text?

We just deployed a method that we think is quite reliable for blocking 98% of posts submitted with code that has improper code formatting (or no code formatting at all).

For example, when I go into Chrome incognito and attempt to ask this question body on Stack Overflow right now:

I needed to add up all the rows for a result. Using the select_sum as follows

Here is the model

function Dues_Paid_Tot($date)
        $query = $this->db->select_sum('Dues_Paid', 'Dues_Paid_Tot');
        $query = $this->db->get('Membership');
        return $query->result();

Here is the controller

function Fiscal2()
    $date = $this->input->post('Select_Date');
        if($query = $this->report_model->fiscal_list($date))
            $data['records'] = $query;
    $data['date'] = $this->input->post('Select_Date');
    $data['Dues_Paid_Tot'] = $this->report_model->Dues_Paid_Tot($date);
    $data['main_content'] = 'report_fiscal_view';
    $this->load->view('includes/template', $data);

I get back:

Oops! Your question couldn't be submitted because:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

This check is limited to users with <= 50 reputation and is performed on questions / answers / edits and suggested edits.

If you see or hear of any cases where this is triggered inappropriately -- or not triggered, and it should have been -- let us know.

  • 2
    Please make it <=50 question only rep or 300 total rep. There are plenty of people with 100/200ish rep that was from runaway upvotes on a standard/silly answer (I'm surprised that "welcome to floating point math" can garner upvotes every damn time) and can't/won't format their questions/answers correctly. By 300 rep, I'm assuming that they've used the code block more than a few times are are familiar with it Commented Jul 13, 2011 at 13:45
  • 1
    we're still tweaking the formula, so let's wait a bit and see before yanking it all the way up to 300. Keep an eye out for badly formatted questions that you think should have been blocked.. Commented Jul 13, 2011 at 13:49
  • Now that's what I call an answer. Code formatting has remained my number-one peeve on SO. Commented Jul 14, 2011 at 1:48
  • @JeffAtwood, you said to let you know if we find any cases where this was triggered inappropriately, and I think I have one. I'd ask on the post here since it's on the Mathematica SE, but I don't have enough rep yet.
    – Izek H
    Commented Dec 30, 2021 at 22:55
  • @IzekH you'd need to let the moderators on that site know via the flag mechanism, that'd be best. happy new year! Commented Jan 1, 2022 at 0:16
  1. I'd be strongly opposed to quarantining a question to prevent answering. There are plenty of helpful people here who are willing to edit questions while you answer them.
  2. It only takes one click to get into edit mode, so I'm not sure what this is saving.
  3. I'm not sure about this one. It places a barrier between a new user and getting an answer. False positives would also be very confusing to even an experienced user. I'm not sure that's the user experience we want.

I think that most new users get the hang of formatting fairly quickly. Most are actively looking for a way to format their code. If it was the same user repeatedly posting questions that aren't formatted correctly, I'd agree, that would be frustrating. If you see that, leave a comment letting them know that their questions will get more (and probably better) answers if they were formatted properly.

  • +1, I agree with responses 1 and 3. But they were really just suggestions. The question was whether something could be done. Regarding point 2, it would save a fair bit of time because it is much quick to select blocks of text in the main question (especially on a large screen) than in the fixed-size edit box. Commented May 23, 2010 at 21:42

Train a language model (bigrams) on non-code regions of all the stack overflow questions. When someone posts something that has a really poor agreement with the model, harass them politely about format.

Or, even, train a perceptron classifier to recognize code blocks, and 001010110 them automatically.

  • +1 for a very creative suggestion. Commented Jun 21, 2010 at 12:05

You must log in to answer this question.

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