-5

I entered over 100 lines of code for my question, and then pressed "Submit" on Stack Overflow. The website gave me an error, saying that my code was formatted wrong. It suggested that I use the Ctrl+K shortcut or the code button to format it. It also said to use indents of 4 spaces.

Initially, I had indented 10 times and was using a 2-space indentation style. I tried cutting the initial indentation to 4, and it didn't work. Then, I changed my nesting style to 4-spaces. That didn't work either. I tried putting the code in backquotes. That didn't work. I highlighted everything, pressed Ctrl+K....didn't work. Pressed Ctrl+K twice...didn't work either.

How can I get my question online?

http://pastebin.com/ugYfbupR (Note: The commented lines were not initially commented. I added them because I thought it would be easier to read on the pastebin.)

Update

The issue has recurred with medium font size. Here's a paste of an answer I have tried to post that has returned the same error message:

Please note that I haven't accommodated any pastebin standards for coding, and this is the post as I initially intended it to appear: http://pastebin.com/GDBMKN0R

enter image description here

29
  • 25
    Just as a note - 100 lines of code is a lot of code for a question. Can you cut it down before posting?
    – ChrisF Mod
    Commented Jul 25, 2011 at 10:33
  • 4
    You've said "it didn't work" several times, but not indicated what actually happened - what changed in the post?
    – Jon Skeet
    Commented Jul 25, 2011 at 10:39
  • 6
    We prefer that all posts be self-contained, meaning that the code is included in the question itself, rather than linked to an external site. That helps to prevent "link rot", where the linked code is now unavailable. This makes the question useless to anyone else in the future, and this site is as much about helping you right now as it is helping others in the future.
    – Cody Gray
    Commented Jul 25, 2011 at 11:24
  • 1
    If you posted over 100 lines of code, you are heading rapidly for a closed question. Most people on so.com don't want to read 100 lines of your code. They expect you to do enough debugging to narrow the problem down considerably from there.
    – Rosinante
    Commented Jul 25, 2011 at 11:56
  • 11
    100 lines of code? 100 lines of code?? 100 LINES OF CODE???
    – user1228
    Commented Jul 25, 2011 at 14:05
  • 13
    @Won't: in Java, that's roughly 2 hello-worlds ;-) Commented Jul 25, 2011 at 14:09
  • 5
    Or how about this... You take a few moments to cut out the crap so that the core of your issue is highlighted in your example? Shouldn't take much time at all for a speedy coder like you. And, on the bright side, the task of reproducing the issue in less code might actually lead you to the solution, and you won't have to ask in the first place!
    – user1228
    Commented Jul 25, 2011 at 16:23
  • 2
    @Jeff Atwood, I used 4 spaces. The way to reproduce the bug is to increase your browser's font size. I tried indenting 4, 8, and 10 on my initial indentation for code blocks, and each of these failed. When I turn my browser's font size to 'medium', I can post long code blocks. When I turn my browser's font size to 'extra large', I can't. Commented Jul 26, 2011 at 8:32
  • 2
    100 lines of code is not nothing, especially on a Q&A site. To ask a question, you should strive for the absolute minimum amount of code necessary to demonstrate or reproduce the problem. People don't want to have to read through all of that code. A lot of people will just skip answering questions that post 100 lines or more of code. I do it myself when I don't have a lot of time. And really, 100 lines of code is quite a lot outside of a Q&A site. A single method should almost never be 100 lines. It's good that you can write code quickly, but it's better if you can write less of it.
    – Cody Gray
    Commented Jul 26, 2011 at 9:36
  • 5
    It's not a "bandwagon argument" or a literacy issue. People will simply not read code in a question when you can't be bothered to take the time to trim it down any more than that. As I mentioned above, unless it's a topic that I'm particularly interested in or I have a lot of time to kill, I won't do it either. It shows apathy on the part of the asker, or even contempt for the time of potential answerers. It's not easy to scan code that you're unfamiliar with. Reading other people's code is one of the hardest things that programmers ever have to do, far harder than writing your own code.
    – Cody Gray
    Commented Jul 26, 2011 at 10:43
  • 1
    And more to the point, I shouldn't have to. You're asking me to help you. The least you could do is make it easy for me to help you. I'm not saying that you shouldn't include code. You definitely should. I'm saying that you should include the minimum amount of code necessary to reproduce or demonstrate the problem. This is a common thread found in any of the "how to ask good questions" guides that you might find online. We link to a bunch of them various places here on Meta and on SO itself.
    – Cody Gray
    Commented Jul 26, 2011 at 10:44
  • 3
    Meta isn't really a "help me" site. That's Stack Overflow. People are a lot more laid-back here, and like I said before, Will was trying to be funny. I don't think "crap" is a curse word or offensive, besides he wasn't calling your code "crap", he was calling the code that is irrelevant to the question you want to ask "crap". It's not crap because it's inherently bad; it's crap because it's not germane to the issue you want to solve. There is just no way that anyone else will read 800 lines of code to help someone else. If you will, well then you're a better person than most of us.
    – Cody Gray
    Commented Jul 26, 2011 at 11:00
  • 6
    @千里ちゃん, I apologize on behalf of Stack Exchange for this interaction. Your question didn't have anything to do with the fact that you were posting 100 lines of code, and therefore it's unfortunate that this comment thread got so derailed onto another subject. Also, Won't's reply was probably well-meaning but because it was informally stated it certainly looks to me like it came across as offensive when it was probably meant with good humor. Commented Jul 27, 2011 at 2:34
  • 8
    In any case it's our fault that you brought our attention to a possible bug and we responded in a less-than-friendly way, so I'm sorry. Commented Jul 27, 2011 at 2:41
  • 2
    It's a nice gesture, but I can't offer forgiveness for all the people who suffer at the hands of a bad process. Thanks. Commented Jul 27, 2011 at 2:47

2 Answers 2

14

For lines that you want to be flush up against the margin, you indent by 4 spaces. Like so:

int foo();

Then you can indent subsequent lines by at least 4 spaces, but up to however many you like. So if you normally use the ratio of 1 tab = 3 spaces, then you can do this:

int foo()
{
   return 42;    // indented 7 spaces (the initial 4, plus 3 for my tab)
}

And so on for however many levels of indentation that you have. You would literally have something that looked like this in the edit window (notice the space on the left margin—exactly 4 characters or more):

    int foo()
    {
       int firstNumber = 12;
       int secondNumber = 3;

       // This function does absolutely nothing useful.
       if (true)
       {
           return firstNumber + secondNumber;
       }
    }

Also note that you can use the "code format" icon in the toolbar to do this automatically. It's the one that looks like a pair of curly braces ({}). Select your entire code block, and then click it. BAM!

Selecting the code block and pressing Ctrl+K has the same effect.

Note also that this is a toggle. If the code is already indented then using the icon or keyboard shortcut will remove the indentation.

2
  • Very cool. Okay, I tried that. Now I'm here. I posted a link, so you can tell me if there are any issues. Also, tab changes the field I have selected. It doesn't indent. You probably noticed this, also. Oh, homonym oh homonym.... Thanks, Chris. Commented Jul 25, 2011 at 12:45
  • 1
    @千里ちゃん: I think that depends on your browser. I don't use Tab anyway, I use the space bar. I've added your code to a new answer; everything worked just fine for me, so I'm not sure what the problem you're having was.
    – Cody Gray
    Commented Jul 25, 2011 at 12:50
3

Copied and pasted directly from linked PasteBin page.

To make this work, the top two lines needed to be indented with 4 spaces, and the comment about 1/3 of the way down needed to be indented with 4 spaces as well.

Both comments were flush against the actual left-hand margin, when they need to be indented 4 spaces in the editor in order to be flush against the left-hand margin of the code block.

Anyway, you can edit this answer and copy and paste what I've done into your Stack Overflow question...

<!-- Pasted for StackOverflowMeta. -->
<!-- I have a huge XML document formatted very much like this (36 lines): -->

<doc>
    <info_type1>
        <element_type1a>
            not_unique_data
        </element_type1a>
        <element_type1b>
            unique_data
        </element_type1b>
        <element_type2a>
            not_unique_data
        </element_type2a>
        <element_type2b>
            not_unique_data
        </element_type2b>
        <element_type2c lang="fr">
            not_unique_data
        </element_type2c>
        .
        .
        .
        <element_typeNxM>
            not_unique_data
        </element_typeNxM>
    </info_type1>
    <info_type2>
        <element_type1a>
            repeat_data_info_type1_element1a
        </element_type1a>
        <element_type2a>
            not_unique_data
        </element_type2a>
    </info_type2>
    .
    .
    .
    <info_typeN>
        <descendants></descendants>
    </info_typeN>
</doc>

<!-- I would like to use PHP or XML to create something like this (78 lines): -->

<datatables>
    <table id="element_type1">
        <element_type1a id="1">
            unique_data
        </element_type1a>
        <element_type1b id="2">
            unique_data
        </element_type1b>
        .
        .
        .
        <element_type1N id="M">
            unique_data
        </element_type1N>
    </table>

    <table id="element_type2">
        <element_type2a id="1">
            unique_data
        </element_type2a>
        <element_type2b id="2">
            unique_data
        </element_type2b>
        .
        .
        .
        <element_type2N id="M">
            unique_data
        </element_type2N>
    </table>

    <table id="element_type2_fr">
        <element_type2a lang="fr" id="1">
            unique_data
        </element_type2a>
        <element_type2b lang="fr" id="2">
            unique_data
        </element_type2>
        .
        .
        .
        <element_type2N lang="fr" id="M"> <!-- There are five languages-- >
            unique_data
        </element_type2N>
    </table>
    .
    .
    .
    <table id="element_typeN">
        <descendants></descendants>
    </table>
</datatables>

<intermediary_tables>
    <table id="intermediary_table_type1xtype2">
        <element id="1">
            <type1ID>1</type1ID>
            <type2ID>1</type2ID>
        </element>
        <element id="2">
            <type1ID>1</type1ID>
            <type2ID>2</type2ID>
        </element>
        <element id="3">
            <type1ID>2</type1ID>
            <type2ID>1</type2ID>
        </element>
        <element id="4">
            <type1ID>2</type1ID>
            <type2ID>2</type2ID>
        </element>
        .
        .
        .
        <element id="N">
            <type1ID>M</type1ID>
            <type2ID>Z</type2ID>
        </element_type2N>
    </table>

    <table id="intermediary_table_typeMxtypeN">
        <descendants></descendants>
    </table>
</intermediary_tables>
6
  • Shouldn't that be pas_de_données_unique for element_type_2c
    – tvanfosson
    Commented Jul 25, 2011 at 14:22
  • The top two lines weren't part of the code in the initial post. I turned them into comments in the paste bin because I thought it would be more readable. I have the same issue with the indented comment lines as well. Commented Jul 25, 2011 at 15:04
  • I copied-and-pasted your code. This is the error message I received, which is the same as the error messages I was receiving before: 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." Commented Jul 25, 2011 at 15:08
  • @千里ちゃん Would it be possible for you to provide a screenshot of the posting interface with the error?
    – Jeremy
    Commented Jul 25, 2011 at 15:22
  • @千里ちゃん: You're going to need someone smarter than me to sort this out. I have no idea why this won't work for you, but seems to work fine for me and others. I suspect it might have something to do with the other question you asked about the CSS layout issues with the site.
    – Cody Gray
    Commented Jul 25, 2011 at 15:32
  • Oh, that's a possibility. I'll see if changing that fixes things. Maybe the detection feature on the site faults at some point, when entering long lines of code. I've posted my question in a more concise format and targeted my issue: math. I got a decent answer and am now just having a syntax error-handling issue. :) Commented Jul 25, 2011 at 16:35

You must log in to answer this question.

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