33

This has bothered me for a while... Ever since the bulky padding and gray background were added to <code> elements, really. But I kept hoping I would get used to it...

...I didn't. It's ugly, it's distracting, it makes me not want to mark inline code and identifiers when I'm answering questions.

The problem

Here's what I'm talking about:

The horror http://shog9.com/so_code_slur.png

Note how the keywords and identifiers pop out of their surrounding text, completely destroying my best efforts to integrate language keywords with the grammar of the sentences referencing them. That's annoying.

But that's not the worst of it. The background shading, coupled with the excessive padding, can lead to something not unlike rivers when code appears on adjacent lines:

Way down down along lazy river road http://shog9.com/so_code_river.gif

This is terribly distracting. What's the point of carefully marking up key parts of text if the result is ugly and distracting?

A solution

First, get rid of the padding:

getting better... http://shog9.com/so_code_no_padding.png

This already helps. The text isn't so broken-up, and you can kinda separate the code on adjacent lines. But it's not enough. That background color still intrudes, tainting what should be clean, white space around the letters. Ditch it, and color the text itself. Maybe increase the weight, if you're really worried about it blending in too much:

ahh... much better http://shog9.com/so_code_subtle.png

There. No gray padding ghetto, no rivers... Much less offensive. At least, I think so. Anyone else?

13
  • 5
    The rivers are gushing in ecstasy.
    – Ether
    Dec 23, 2009 at 5:38
  • 11
    That animated gif is irritating me terribly. Dec 23, 2009 at 7:47
  • provide examples of actual Stack Overflow posts where this is a problem, please. I assumed your images were real posts, but I'm not finding them -- which means this question is now highly suspect. Dec 23, 2009 at 9:52
  • 1
  • 2
    I sincerely hope you tried to search for absinthe.h... (The text in the first image was completely fake - I needed something short since the post was getting long. The "river" example is a real answer, but without the paragraph break present in the original - it can be found here: stackoverflow.com/questions/1735255/… )
    – Shog9
    Dec 23, 2009 at 9:58
  • well, I edited your post so that it's less obnoxiously filled with "every-named-thing-ever-mentioned-must-be-code" and more focused on using <code> to highlight ... y'know ... actual code. Dec 23, 2009 at 10:04
  • and please note when you wrote "the success of your XMLHttpRequest call" that was a TREMENDOUS missed opportunity for YET ANOTHER <code> block. How will this post compile, if you don't properly and obsessively mark every single thing that could possibly be code.. with the <code> tag? Dec 23, 2009 at 10:06
  • I also missed the parens on the first make_request comment. But... You left the tags code-formatted? Hmm...
    – Shog9
    Dec 23, 2009 at 10:13
  • 1
    I think the point is that obsessively marked up ANYTHING is going to be hard to read, which is why I am resisting this so strongly at the moment. You're arguing from a case of "support my abuse!" and I am not going to be your enabler. The plain fact of the matter is, it's easier to read, PERIOD, when not every third word is obsessively and unnecessarily marked up as code. Just like bold, or italic, or.. well.. anything, man. You have not convinced me. If anything, I am more resolute in my position than when we started. Dec 23, 2009 at 10:16
  • 1
    In fact, I'd argue that "wow, it looks really bad when I mark up every third word as code" is in fact [status-bydesign] and intentional. That SHOULD look bad. Because YOU SHOULDN'T DO IT. :) Dec 23, 2009 at 10:18
  • 16
    See, I'm having trouble following your logic here. If every third word is... code, then what's the harm in marking it up that way? Oh right - it looks lousy. But that's fixable, which is the whole reason for my bringing this up. Granted, I can avoid using markup for the sole reason that it looks lousy, but that can apply to anything: if you made lists look terrible, folks would stop using lists, if you made paragraph breaks insert ten lines of whitespace, then folks would find a way to avoid that, and so on. Is there some reason apart from the lousy styling why I shouldn't mark code?
    – Shog9
    Dec 23, 2009 at 10:33
  • 1
    This is like arguing that it's OK for a post to be an enormous list of bullet points. Uh, no. If every third word is code, then you're not writing prose, you're writing code, and it should be a <pre> block with .. actual code. Not enough words. So either add more words that explain around the code, or just make it all code and forget about prose altogether. Things that are bad (tons of marked up code with almost zero plain, readable explanatory prose) should look bad. Dec 23, 2009 at 10:40
  • 1
    Hmm... Now that makes some amount of sense! I do like having some indicator for identifiers, and don't like ugly, but if it serves a purpose then so be it - 'suppose I could always follow the MSDN style and use italics for identifiers. Any chance I could persuade you to add a third answer consisting of that comment?
    – Shog9
    Dec 23, 2009 at 10:47

8 Answers 8

4

Adding this answer by request.

This is like arguing that it's OK for a post to be an enormous list of bullet points. Because you have all these points you're trying to make, natch! Uh, no.

If every third word is code, then you're not writing prose, you're writing code, and it should be a <pre> block with .. actual code. Not enough words. So either add more words that explain around the code, or just make it all code, slap it in a 4-space-indented <pre> and forget about prose altogether. Things that are bad (tons of marked up code with almost zero plain, readable explanatory prose) should look bad. So if you're marking every third word as code and complaining that it looks bad, that's intentional!

Too much <code> is overwhelming, just like too much bold, too much italic, too much ALL CAPS, too much … you name it. There should be a healthy mixture of readable, explanatory prose interspersed with small snippets of code for emphasis.

So, rather than using <code> to mark up simple identifiers that are only "code" in the loosest sense of the term, use italics.

2
  • 4
    I can accept that. More importantly, next time I run into "rivers of code" I can fix that!
    – Shog9
    Dec 23, 2009 at 10:57
  • 2
    How about HTML's <var> for those that care enough to type it? (SO---but not SU, I noticed---already does something similar for <kbd>.) Italics would still be possible, of course.
    – Gnome
    Jan 2, 2010 at 21:39
7

The genesis of this feature, for reference:

I have a different preference for how code-in-text could be formatted: change the background colour for that section of the text too. That's a lot clearer than quotes in my view, as well as not interfering with code which uses quotes.

Posted by Jon Skeet on July 5, 2009
Make it easier to put quotes around code samples

I for one agree with Jon, and I am now quite annoyed by this question as I think you are cherry picking examples (and/or making crap up) to show abuse, when anything can be abused. Like my bold example.

Here's a more typical post where I think the background of the <code> block makes it quite readable, far more readable than just changing the font -- as Jon Skeet noted.

http://img6.imageshack.us/img6/5459/img1y.png

Do you really find the backgrounds objectionable in these code blocks?

If so, then I guess de gustibus non est disputandum.

2
  • So that's where it came from! Well, shucks... Pity I didn't take the time to mock up screenshots at the time.
    – Shog9
    Dec 23, 2009 at 10:01
  • 1
    Well, I apologize for misleading you - that wasn't my intention! I'd hoped to illustrate a problem that can arise when code-formatted identifiers are mixed into text, or happen to align on adjacent lines, things I observe regularly on a small scale (adjacent punctuation or 2-3 lines together mostly) and occasionally on a larger scale (at which point I'll make some effort to change how the lines wrap or paragraphs break). So yes, it's possible to mitigate the problem without altering the styles... But it would be nice if that wasn't necessary!
    – Shog9
    Dec 23, 2009 at 10:26
5

It's so obvious and clean, one wonders why this cannot be implemented immediately. Was your mockup above just a mockup, or do you have some CSS modifications in mind for this?

IMHO, insertion text with a differently-coloured foreground is generally more readable than a differently-coloured background (assuming that sufficient contrast remains).

14
  • As a programmer I sincerely hope your "why [can't this] be implemented immediately" is in jest... Dec 23, 2009 at 6:48
  • 3
    @Farseeker: if it's a simple matter of changing some CSS (I'm not saying it is, although I'd be surprised), that's pretty simple to include in the next push to production.
    – Ether
    Dec 23, 2009 at 6:59
  • a new color in text is never, ever going to happen. Stack Exchange has massive trouble with the limited # of colors we use now. So my advice is to restabilize your inner chakras and let it go. Dec 23, 2009 at 9:23
  • 3
    It can be implemented immediately. By you! Using Stylish, or a similar means of modifying site-specific CSS on the client side. That's why those tools exist, because while you can't please everyone, it can be made possible for people to suit themselves. Dec 23, 2009 at 12:23
  • 2
    There's a potential solution to the color problem, anyway: Use one of the colors already part of the site's palette. Problem solved. Personally, I love Shog9's original suggestion; I'm liable to implement the user style solution from John Rasch for it.
    – John Rudy
    Dec 23, 2009 at 18:40
  • using a bright, arbitrary color (outside of a block) means it can now be mistaken for a hyperlink. Like "Dialing For Internet Dollars", above, which is a hyperlink.. Dec 23, 2009 at 19:42
  • 1
    You could always underline the hyperlinks. Just sayin'...
    – Shog9
    Dec 23, 2009 at 19:55
  • (btw, that is why the code blocks were originally just a code font, until that was changed at the behest of the community.) Dec 23, 2009 at 20:02
  • No, see - it'll totally work out. Because the underlines will make links stick out like sore thumbs, and thereby discourage excessive linking. Remember that Wikipedia issue you were worried about? I'll be that'd never happen if all links had big fat underlines under them. I guess you could always give links a background color too, just in case folks didn't get the hint...
    – Shog9
    Dec 23, 2009 at 20:04
  • Wouldn't monospace be sufficient for code markup? :)
    – Ether
    Dec 23, 2009 at 20:04
  • @Æther: no. It didn't stick out enough that way. So when someone made a suggestion that got... essentially support... Jeff saw the opportunity to teach us all a good lesson about the over-use of code tags.
    – Shog9
    Dec 23, 2009 at 20:08
  • 3
    Summary: the point (for everyone but Jeff at this point I think) is that it shouldn't stick out. So we have two options: abandon the use of the tag altogether (and do something else as a workaround), or actually make it look nice. Did I get that right?
    – Ether
    Dec 23, 2009 at 20:12
  • no, you forgot the actual point: like bold, hyperlinks or any other tag, why not use it.. y'know.. in moderation? When you want to emphasize something and bring attention to it? Seems there's two philosophies here: everything that CAN be code (or a hyperlink) ABSOLUTELY MUST BE.. and my position, which is that you should only mark code (or a hyperlink) when it adds significantly to the text. Dec 23, 2009 at 20:17
5

While I agree with Jeff,
it doesn't hurt to use a user style:

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("stackoverflow.com") {
  p code {
    padding:0 !important; 
  }
}
5

Building on John Rasch's answer with Shog9's formatting (see comments on that answer by Æther), here's a complete userContent.css file for Firefox to address this. Obviously, you'll want to season to taste.

This covers both in-post and in-comment <code> blocks.

Save as userContent.css, and place under your Mozilla Profile's chrome directory:

  • On Windows, this will likely be a variant of %AppData%\Roaming\Mozilla\Firefox\Profiles\profileName\chrome. (It may be in Local for you; mine is in Roaming.)
  • On MacOS, this will likely be a variant of ~/Library/Application Support/Firefox/Profiles/profileName/chrome/, however currently my Mac is not loading from there.

@namespace url(http://www.w3.org/1999/xhtml);

@-moz-document domain("stackoverflow.com") {
  p code, .comment-text code {
    padding:0 !important; 
    background-color: white !important;
    color: #602020;
    font-weight: bold;
  }
}

@-moz-document domain("meta.stackoverflow.com") {
  p code, .comment-text code {
    padding:0 !important; 
    background-color: white !important;
    color: #602020;
    font-weight: bold;
  }
}

@-moz-document domain("superuser.com") {
  p code, .comment-text code {
    padding:0 !important; 
    background-color: white !important;
    color: #602020;
    font-weight: bold;
  }
}

@-moz-document domain("serverfault.com") {
  p code, .comment-text code {
    padding:0 !important; 
    background-color: white !important;
    color: #602020;
    font-weight: bold;
  }
}
3
  • 2
    *sniff*... It's... beautiful!
    – Shog9
    Dec 23, 2009 at 19:38
  • 2
    +1 - I am totally using this one now. Next on the list will be implementing a Hot Dog Stand theme for SO
    – John Rasch
    Dec 23, 2009 at 19:46
  • 1
    Beats Greasemonkey any day.
    – snicker
    Dec 23, 2009 at 19:50
4

Obligatory Greasemonkey solution:

// ==UserScript==
// @name          "FORMATTING OF INLINE CODE IS UGLY AND CAN RESULT IN RIVER-LIKE PATTERNS WHEN USED FREQUENTLY" or "HOW I LEARNED TO STOP WORRYING AND LOVE THE SHOG9"
// @namespace     http://scfs.me/
// @description   Will reformat the wonderful inline code elements on S[OFU] to look more awesome.
// @include       http://meta.stackexchange.com/questions/*
// @include       http://stackoverflow.com/questions/*
// @include       http://superuser.com/questions/*
// @include       http://serverfault.com/questions/*
// ==/UserScript==

(function(){
    function jqwait() {
        if(typeof unsafeWindow.jQuery == 'undefined') { 
            window.setTimeout(jqwait,100); 
        } else { 
            makepretty(unsafeWindow.jQuery);
        }
    }
    jqwait();
    function makepretty($) {
        $("code").css({'padding' : 0, 'color' : '#600', 'background-color' : 'transparent'});
    }
})();
4

Ok I'm going to add another answer...

Jeff said:

So, rather than using <code> to mark up simple identifiers that are only "code" in the loosest sense of the term, use italics.

Italics for code identifiers still look lousy unless it's a monospaced font, which is generally what people are going for when they use ` markup. That's definitely what I use ` for (except in comments when ` is all there is to post a few short code snippets). So perhaps we could benefit from having a new style element for code identifiers? It could use styling similar to what Shog9 suggested originally, but can leave the styling of the code div block alone.

There's no reason why the code div and code span elements need to be styled the same.

PS. There's way too much snarkiness and personal attacking going on in this thread. It's not about me, it's not about you, it's about making the site better. So knock it off already!

3
  • Well, you guys disagree with Jon Skeet and myself on this one. Shrug. Dec 23, 2009 at 19:03
  • 1
    Disagreement is fine. There's just no need to make it personal. But I suspect you've heard this before.
    – Ether
    Dec 23, 2009 at 19:16
  • well, if it hurts when you do that, stop doing that. And by "that" I mean making every third word <code>. That's 100% [status-bydesign]. Dec 23, 2009 at 19:20
0

99.9% sure we won't be "fixing" this problem by adding another noisy color to the page.

Have you considered not using <code> blocks so aggressively in your text?

I don't know if you noticed but any text with too much of a particular formatting style becomes difficult to read. Perhaps using such formatting styles in moderation would be a more effective solution?

Treat the disease, not the symptoms.

EDIT: is this even a real example of a Stack Overflow post, or a strawman you constructed? I can't find any of the strings in the "example" you provided, either through Google search or Stack Overflow phrase search.

7
  • 2
    I consider it every time I look at the preview. Then I remember how great it used to look, with all keywords and identifiers subtly indicated by no more than a change in font... And I think, this sucks now. This entire post would look better if I copied the preview and pasted it back into the editor. But it doesn't have to, it didn't used to, and maybe, just maybe, it'll one day again pay off.
    – Shog9
    Dec 23, 2009 at 5:55
  • 7
    Just out of curiosity... what's your fascination with using background color? I no more than post my last comment, than I'm presented with yet another scenario, that of my own name graylighted next to the comment. You were one of those people who ruined textbooks with those wretched yellow markers, weren't you!
    – Shog9
    Dec 23, 2009 at 5:59
  • well, people complained that the font alone change on code blocks was too subtle. Now, people complain that having a background color for code blocks is too noisy. I will leave reducing this equation to its constant as an exercise for the reader. Dec 23, 2009 at 6:15
  • 2
    Yeah, I know... that's why I've been biting my tongue 'til now. But i figured, it hasn't stopped irritating me, so I'll toss it out... if it's declined, then I'll install a custom stylesheet and forget about it.
    – Shog9
    Dec 23, 2009 at 6:29
  • 4
    Dude, it's a site about programming. There's going to be <code> blocks!
    – Ether
    Dec 23, 2009 at 9:08
  • yes, but every time you mention a programming term does not mean you MUST make it a formal <code> block. That's like those wikipedia articles where every third word is linked to a wikipedia article, because, y'know, those terms are TOPICS, man! Dec 23, 2009 at 9:21
  • 3
    Man, what's with the wikipedia hate here today? Anyway... I tend to rely on code markup when I'm: A) referencing code that the OP has posted (beats mass-quoting entire code blocks), or B) referencing key language or API functions / keywords. Either way, it's helpful to mark them in some way as being... code. Not just random terms I happen to like, but terms that have some meaning apart from that granted by the context I've placed them in. Most sites just change the font, but since that's apparently a problem here, I'm trying to suggest a compromise that isn't painfully ugly. Italics maybe?
    – Shog9
    Dec 23, 2009 at 9:39

You must log in to answer this question.

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