What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 133 Stack Exchange communities.

As far as I can tell, the code window here is always 79 characters wide. If there are lines longer than 79 characters, there will be a horizontal scroll bar shown, to see the rest of the code that does not fit in those 79 characters.

Example:

public static void fillCheckList(string ListType, int RecordNum, CheckBox chkRequired, TextBox txtComplete)
    {
        fillCheckList(ListType, RecordNum, chkRequired, txtComplete, null);
    }

When it could look like this:

public static void fillCheckList(string ListType, 
                                 int RecordNum, 
                                 CheckBox chkRequired, 
                                 TextBox txtComplete)
{
    fillCheckList(ListType, RecordNum, chkRequired, txtComplete, null);
}

At least for me, the second example is a lot more easier to read, because I can see everything without using the scroll bar. This was not even close to the longest lines here: there are a lot sample code here, especially Xcode generated iPhone code, where lines are over 150 characters long. Using a scroll bar to see what is actually happening in the code is pretty difficult; Copying the code to an editor locally is a lot better solution.

Are there people who actually think that the first example is easier to understand or is it too difficult to split long lines before posting them here?

share|improve this question

migrated from stackoverflow.com Mar 5 '10 at 15:30

This question came from our site for professional and enthusiast programmers.

2  
Time to migrate: one minute, sixteen seconds. That has to be close to the record. –  mmyers Mar 5 '10 at 15:33

7 Answers 7

Because they don't care.

P.S. I always split any code that I post so that it is immediately readable without scrolling.

share|improve this answer

Being optimistic: because they didn't notice it overflowing (or at least - that's why I've done it in the past).

If you see code like this, and you've got at least 2000 rep - fix it!

share|improve this answer
    
It's not the job of 2000s to perform corrections for lazy ones. –  user136634 Mar 5 '10 at 15:32
13  
@Developer Art: I hope you're in the minority. –  mmyers Mar 5 '10 at 15:33
3  
@Developer Art - you're assuming it's because people are lazy. In my case, it's because I'm not very observant. And besides, it's not a job, it's a privilege to help the site that has helped me be easy to use for people who may be new. –  Dominic Rodger Mar 5 '10 at 15:43
    
@Developer Art - ok, so you may have only asked a couple of questions on SO and not feel any compulsion to make corrections and fixup badly formatted code. But for the answers I get (quickly) I'm happy to fix this stuff as a return favour. It's why we have edit buttons, it's how we try and maintain quality. –  The Anti-Santa Mar 5 '10 at 17:14
    
Well, I probably was too harsh, sorry. Yes, I myself do corrections now and then and I absolutely don't mind it, even enjoy it. –  user136634 Mar 5 '10 at 17:17
    
I'd like to start a campaign to get people to take another look at their code snippets before they post. I lurked for a year until I started answering more questions. many of the questions that I answered this week were obvious once I reformatted their code samples. –  Henk Langeveld Aug 6 '12 at 15:17

Two reasons that I don't see listed yet:

Shortest Answer: On questions that a bunch of people answer quickly, there seems to be a preference towards people thinking shorter answers (code-wise) are better (i.e. more efficient). Shorter in the visual sense is fewer lines of code.

Verified Working: When you grab a sample of code from existing production code that you know works, any change you make to it might break it. You might be trying to add some line breaks and you end up deleting a comma or semicolon by accident. I've seen countless examples of "simple" edits to posts that kill the code.

share|improve this answer

Because they're lazy.

share|improve this answer

Most people have large displays where they edit the code in the IDE (potentially to check for validity before posting) and copy and paste it.

share|improve this answer
1  
I agree that this is probably the case, but my question was more about why they don't modify the code, when they see the horizontal scroll bar appearing. –  Tuomas Pelkonen Mar 5 '10 at 16:09

There are many different reasons why a user would leave code like this.

They could...

  • Not care
  • Not realize how it will be displayed to other users
  • Intentionally be making it difficult to read
  • Assume everyone else understands the code as well as they do

The question is not why they do this, the question is, how can we actively make this content more available to everyone?

The answer to that, IMO, is to let the many helpful 2k+ users reformat the code and/or leave comments on the question to indicate to the user that posting code in a more readable format will let the community give a better answer to their question.

share|improve this answer
    
Has the 2k+ rule changed? I got bumped to over 200 rep only this week, and I was able to submit corrections, and have been using that feature quite a lot in these last few days. –  Henk Langeveld Aug 6 '12 at 15:20
2  
@Henk: This answer is a little outdated. A new feature called Suggested Edits was introduced that allows lower-rep users edit posts subject to peer review. –  Jon Seigel Aug 6 '12 at 19:21

Add one line to the style guide/posting FAQ:

When you enter a question, take a minute to look at your code samples to see if you can improve the layout. Try to add line breaks (and backslashes if necessary) to prevent overly long lines and scrollbars.

share|improve this answer

You must log in to answer this question.

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