1

Is it advisable to use the code-block for inline-code like DataGridView or WinForms.Webbrowser?

eg: Windows Forms Webbrowser Full history

Some Mods also do it: Null Pointer exception in C#

And should I highlight the second appearance too?

E.g at Wikipedia you only highlight the first appearance.

11
  • would be nice if the downvoter leaves a comment with a reason.
    – Vloxxity
    Commented Nov 16, 2012 at 16:46
  • 10
    It would be nice if people read the FAQ before posting on any site (including Meta).
    – yannis
    Commented Nov 16, 2012 at 16:53
  • 6
    Welcome to Meta! What Yannis was trying to point out is that voting works differently on meta sites. It often indicates disagreement, rather than "your question makes no sense." I can't speak for everyone, but I downvoted you because I agree with Michael and ThiefMaster (i.e. think it's not advisable to use code formatting for "highlighting").
    – Pops
    Commented Nov 16, 2012 at 17:12
  • 3
    Please don't use backticks to "highlight" random words. See: meta.stackexchange.com/questions/137755/… Commented Nov 16, 2012 at 17:51
  • 1
    If you're introducing a technical term, it might be appropriate to highlight it by using italics (surround it with * characters). Commented Nov 16, 2012 at 18:07
  • 2
    but WinForms.Webbrowser and DataGridView in this case is a piece of code... so i could highlight it !?
    – Vloxxity
    Commented Nov 18, 2012 at 22:12
  • @PopularDemand You can disagree with a Statement, but how do you disagree with a question? I asked it because im not sure, and i din´t say someone should do it.
    – Vloxxity
    Commented Nov 21, 2012 at 13:56
  • 3
    @Vloxxity it's bit more complicated than "disagree with a question". It's more like "disagree with the idea behind the question", in this case you are suggesting that certain words need to be backticked in posts and right now 7 users agree with this idea while 9 disagree. Hope this makes more sense now? Commented Nov 21, 2012 at 14:45
  • @Vloxxity Sha Wiz Dow Ard summed up what I meant. Your post asks "is it advisable to do X" and "should I do Y." In this case, upvotes might indicate yes (i.e. it is, and you should) and downvotes would indicate the opposite.
    – Pops
    Commented Nov 21, 2012 at 14:59
  • 1
    @PopularDemand yeah i think your right... but those downvotes feel like a punch in my face: are you dumb or why are you asking that, imo they should rather upvote the answer that says no you shouldn´t
    – Vloxxity
    Commented Nov 21, 2012 at 15:23
  • 2
    @Vloxxity I see where you're coming from, but it's just something you have to get used to. It's like learning a new language. "Blesser" is a word in English. It's also a word in French. But even though they look the same, the French one and the English one have totally different meanings. So, please don't take the downvotes the wrong way, because even though they look like the painful downvotes you're used to, they don't mean the same thing.
    – Pops
    Commented Nov 21, 2012 at 15:23

4 Answers 4

16

That's not a highlight; that's a code block. And no, it's not appropriate to use it to highlight technical terms. it should only be used on blocks of code:

public bool IsActive
{
    get { return _isActive; }
    set { _isActive = value; }
}

or inline code: _log.Debug("Setting hyperspace mode");

You can occasionally get away with using it to call out things like class or object names ("Why must I initialize a Dictionary this way?"), and angle brackets hide unless you use <code blocks> to show them, but try to limit that. It gets annoying awful fast, to see code formatting littered throughout your text.

8
  • 2
    You have to code-format angle brackets if you want them to be visible...
    – AakashM
    Commented Nov 16, 2012 at 16:53
  • also note that it causes the text between the ticks to be treated as literal text, not HTML or markup. Dictionary<string, string> doesn't display right in an answer if it's not wrapped in backticks.
    – Servy
    Commented Nov 16, 2012 at 16:53
  • 5
    It is also helpful to use backticks to differentiate keywords in code from words in your sentence. If you have an in in your code, you are suggesting that someone use for for their loop or using using instead of Dispose then it's much harder to understand without any backticks.
    – Servy
    Commented Nov 16, 2012 at 16:55
  • You're right about the angle brackets; incorporated. Commented Nov 16, 2012 at 16:58
  • 1
    Oh really: Dictionary<string, string>
    – Eric
    Commented Nov 19, 2012 at 8:28
  • 1
    @Eric in an answer. You can even see this in the preview window: start an edit of this very answer and remove the backticks around <code blocks>; note that the words disappear in the preview pane.
    – AakashM
    Commented Nov 19, 2012 at 8:51
  • 2
    @AakashM using the HTML &lt; and &gt; you can get your precious angle brackets to appear in an answer, but it doesn't work in comments. Commented Nov 21, 2012 at 13:52
  • @RichardJ.RossIII ... or you could just use backticks, which work in posts and comments
    – AakashM
    Commented Nov 21, 2012 at 14:07
11

No, you should not "highlight" any of them. The backtick operator is meant for code highlighting and those words are not code. However, if something in your text is actually code or code-like (a filename might qualify for example) using this formatting is fine.

On a side-note: Edits adding such formatting should be rolled back (or rejected if just suggested) with extreme prejudice. Slapping trouts into the face of the editor would also be a good idea.

4
  • 1
    Sometimes adding code formatting can dramatically improve the readability of a post, when distinguishing English-y keywords like for or is, or when a non-fixed-width font makes an expression too dense with narrow characters like parentheses.
    – McCannot
    Commented Nov 16, 2012 at 17:26
  • for etc in such a context would be code. And thus highlighting those words would be perfectly fine.
    – ThiefMaster Mod
    Commented Nov 16, 2012 at 17:58
  • 1
    Ah, I misunderstood, sorry. Actually, I'd say not everything that could be considered code really needs highlighting, and edits that do nothing but put backticks around a bunch of perfectly readable class or method names annoy me (that they often ignore other formatting issues doesn't help either).
    – McCannot
    Commented Nov 16, 2012 at 18:06
  • just updated the question see edit...
    – Vloxxity
    Commented Nov 18, 2012 at 22:20
3

Bad:

I have DataGridView in my form, my variable is myGridView. myGridView is being set in Page_Load and the DataGridView is loading from a data source which reads from database.

Good:

I have DataGridView in my form, my variable is called myGridView. This variable is being set in Page_Load and the DataGridView is loading from a data source which reads from database.

My $0.03:

  1. When the term sticks out already, no need to backtick it. DataGridView got three capital letters and will stick out in any context so can't see reason to wrap with as inline code, unless of course it is part of a longer code. You can use DataGridView to make it more noticeable.
  2. In case of variable names this is more reasonable to mark it as inline code, but try to not use the name too many times.
  3. All in all, there isn't one rule for this; each case is specific and depends on the context.
9
  • 2
    You must hate my answers sometimes, then. I would have code-blocked everything in your first sample except data source and database. Commented Nov 21, 2012 at 13:52
  • @Frédéric not hate; just think it's incorrect, reject suggested edits of that kind and on extreme cases rollback such edits, though I did it only once or twice. Commented Nov 21, 2012 at 13:57
  • Sure, we agree about those edits, but I was under the impression this question also addressed use of code blocks in original content. Now I'm wondering how I would react if someone edits one of my answers to remove some of the code blocks because meta says they're not appropriate ;) Commented Nov 21, 2012 at 14:00
  • 1
    @FrédéricHamidi yeah i would also highlight the first appeareance of 'myGridView' and 'Page_Load' because those are names of functions or code objects.
    – Vloxxity
    Commented Nov 21, 2012 at 14:01
  • 1
    @Vloxxity, I would actually code-block all instances, not only the first ones. IMHO the "Wikipedia pattern" makes sense for hyperlinks but not for other content. (On the other hand, I do not code-block hyperlinks because I think the result is quite hard to read, especially on visited links. It's complicated.) Commented Nov 21, 2012 at 14:05
  • i havent codeblocked the hyperlinks thats a quote-block.
    – Vloxxity
    Commented Nov 21, 2012 at 14:08
  • @Vloxxity, oh, I wasn't referring to that :) I was just saying I either write, say, $.ajax() or $.ajax() but not $.ajax() (harder to read on SO). Commented Nov 21, 2012 at 14:10
  • ah okay didnt get that, also some mods like to do that see: meta.stackexchange.com/questions/100128/…
    – Vloxxity
    Commented Nov 21, 2012 at 14:13
  • @Vloxxity mods are no gods; when it comes to those things their opinion doesn't really have more weight than yours, Frédéric's or my own. Commented Nov 21, 2012 at 14:43
1

I'd argue that the semantic way of highlighting these terms are via the <i></i> tags in HTML5, but since StackOverflow's markdown doesn't support them you can do one of the following:

  • Do it yourself, Like so
  • Do nothing.
0

You must log in to answer this question.

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