When a code snippet is long enough to prompt scrolling (especially horizontal scrolling), it would be helpful to offer a link to view the code snippet in a new window.

I'm thinking that the link should be positioned below the snippet, since most people will decide to use it after scanning the part of the snippet that is visible without scrolling.

  • 1
    Alternatively, I kind of like auto-expanding on hovering, if the width allows for it. Like one sees in SyntaxHighlighter on many blogs, like here.
    – Arjan
    Commented Feb 2, 2013 at 20:05
  • A lot of chatter from years ago about hypothetical ways to resolve this. Pop it in a new window, wide enough for a modern monitor to view. Done. Especially the objective-c comment below, seriously.
    – blu
    Commented Apr 30, 2013 at 1:09

6 Answers 6


I have a strong dislike of the scrollbars-within-scrollbars that code snippets introduce. I do tend to edit my samples to avoid it, which I guess is part of the desired behaviour Jeff is going for. I know in the past Jeff has said that snippets should be short, but sometimes a bit of verbosity is unavoidable.

I'm not sure I would want a new window, but perhaps some CSS-based truncation and JavaScript expansion would be in order. Or perhaps some font scaling code, if such a thing is deemed practical.

  • Same here, as for editing. But I always wonder if others (other OS, other browser) will see the same I see. :-)
    – Arjan
    Commented Jan 23, 2010 at 11:01
  • 1
    Or like, "line wrap". Seems too difficult for many text editors. +1 for strong dislike of scrollbars-within-scrollbars. Commented Mar 22, 2010 at 15:39
  • I agree with you, I thik it would be very useful to have a way to see the code expanded easily.
    – Dzyann
    Commented Oct 17, 2013 at 15:24

This would be a godsend for Objective-C posts. Every time I have to come here for a Cocoa development question, I end up having to copy the code into an editor that I can stretch out thanks to the ridiculously long method signatures.

You try distinguishing - (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { from - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { (taken from the code I'm looking at right now) on a slim window with horizontal scrolling and tell me if your eyes aren't bleeding by the end of the day. Sure people could break up the lines when they post. But they don't!

So, Stack Overflow: Please please please do this for the sake of all us Mac developers!

  • i don't work in objective c, but... surely you can break that across lines on the colons or something can't you??
    – Kip
    Commented Jan 15, 2010 at 19:24
  • 8
    No disrespect to your language and the great possibilities you guys have on the iPhone and all, but I think I just decided never, ever to get near Objective-C. :)
    – Pekka
    Commented Mar 23, 2010 at 21:30

If you're interested, I built a greasemonkey script that helps solve this problem by allowing you to click the code region and have it expand to show all the code at once.


This is more of a brainstormy "what if" type suggestion. What if SO had some kind of pastebin that was integrated with the site? Or if that wasn't possible, why not instead offer some kind of integration with pastebin or maybe even github's gists?


Here is an idea: we could use something like etherpad to post code snippets, that way someone could actually edit the code and save a revision, then link to the revision with their answer. That way you could see all the possible answers for your question via revision

For example: http://beta.etherpad.org/p/r.RcW61c4F4f7MdcKa

The advantage over pastebin is that Etherpad is real time so updates can be seen / discussed instantly.

  • or pastebin.ca or another text-snippet-hosting site. Commented Mar 23, 2010 at 21:38
  • 2
    Except I find that the etherpad link above is now broken - perhaps not so desirable.
    – sage
    Commented Dec 11, 2010 at 20:55

My opinion is that long (or numerous) code blocks (and/or images) should be discouraged while asking and editing questions, in much the same way duplicate questions are discouraged.

If the user continues to post the question with ridiculously long/numerous code blocks or images, despite the warning, then they should be hidden and replaced with "show/hide" links that, of course, shows or hides each block in its entirety (or maybe all blocks with just one link if there are too many). It would also be nice if these links were available on anything longer than maybe 3 lines, or maybe even every block, but not automatically collapsed.

Not only will this make it easier for those reading the question to show only the information they need to come up with an answer, but it also provides further discouragement to the user who asked the question, because now the people who might usually answer are less likely to spend time on a bloated question. They see that certain parts are already collapsed, which they will soon learn is usually bad news.

I mean, look at this mess:

How to handle custom Java exception in Flex app

This is just awful. Now, maybe all of that is necessary, I don't know (I doubt it). But if those were all collapsed, you could take one look and know without scrolling that there is probably too much information being presented here.

You must log in to answer this question.

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