51

A question came up in which the asker demonstrated cross-browser rendering differences between two complete HTML documents, one with a DOCTYPE:

<!DOCTYPE html>
<img style="width: 100%; height: 100%;" src="image.jpg">

and one without:

<img style="width: 100%; height: 100%;" src="image.jpg">

The only two things missing from either document are the title element, which has zero impact on rendering since it's not even part of the document body, and an alt attribute on the img element, that only affects rendering in some browsers when the image cannot be displayed, and otherwise has zero impact on rendering as with the title element. (The second snippet is also missing the DOCTYPE itself, but it's there as a point of comparison; the entire point of the question is that the desired behavior is only seen when it's left out.)

But one commenter pointed out that the samples were missing the <html> and <body> tags and their markup was invalid and solutions to their problem would not work reliably for that reason (which, of course, is wrong; it is invalid with no side effects for the reasons I just stated above). Another commenter asked what would happen if the asker loaded valid HTML, implying that it would make any difference to rendering in this case (which, again, it doesn't — there's just one img element).

A third mentioned that the tags are indeed required under certain circumstances — except this wasn't one of them, but I was happy to clear up something they misunderstood about the spec since they made an effort to cite it, unlike the others.

So the asker was forced to add <html> and <body> tags to their snippets, tripling the line count on the former and quintupling it on the latter (they have since rolled this back after I corrected everyone else in the comments):

<!DOCTYPE html>
<html>
  <body>
    <img style="width: 100%; height: 100%;" src="image.jpg">
  </body>
</html>
<html>
  <body>
    <img style="width: 100%; height: 100%;" src="image.jpg">
  </body>
</html>

Like, why is this necessary? There are no attributes on either start tag, and there is nothing but a single img element in the entire document. All it does is make it more difficult to see the problem at hand: that browsers scale the image differently depending on whether or not the DOCTYPE is present.

This is not an isolated case. This happens on a daily basis in and/or questions. Askers are forced to add boilerplate that they know isn't required and has zero impact on the problem just because multiple commenters incorrectly think that it is.

The only good reason I can think of for adding these tags is so that readers know these are in fact complete HTML documents, not incomplete fragments. But no one says that. Anyone pointing out missing <html> and <body> tags only does so because they think leaving them out makes a page invalid (this is only true in XHTML, who writes that anymore?). And a lot of people think so. Those who think the snippets are incomplete fragments say something along the lines of "Please provide the complete HTML" instead. No one has said that here.

Don't people tend to obsess over the M in MCVE to the point where even a single line of boilerplate will set them off? (Note that the C and V are met even when the boilerplate isn't there — that's why it's called boilerplate.) Don't people dislike HTML for how verbose it can get? So why are readers complaining when the asker is doing them a favor by leaving out unnecessary bloat? Where is the line drawn?

36
  • 9
    "Where is the line drawn?" -- wherever the majority decides it is, just like everything else (including up-voting blatantly poorly-researched and useless questions, for example). Frankly, I find your title leading; if the code is literally "not required", then of course it may be omitted. I think it's (only slightly) more interesting to discuss true boilerplate that is required, but can be omitted without hurting the clarity of the question. But at the end of the day, the real problem is when people give in and edit their post instead of just responding in the comments. Commented Dec 12, 2017 at 6:24
  • 23
    On other tags like c# people leave things out all the time. If you're demonstrating the functionality of a method, you give people the method. Never mind the fact that it should be in a namespace and a class, that's just fluff as far as the question is concerned. The people reading are assumed to be smart enough to know that it's not a complete program, just a snippet of one.
    – Lauraducky
    Commented Dec 12, 2017 at 6:29
  • 21
    @Lauraducky: That's why I come to Stack Overflow. When I ask questions, I expect readers to be smart enough to know how to fill in the blanks. Sadly, certain tags don't get so much luxury anymore...
    – BoltClock Mod
    Commented Dec 12, 2017 at 6:36
  • 1
    I suspect the answer will be: "It depends."
    – Booga Roo
    Commented Dec 12, 2017 at 6:41
  • 1
    I don't work much on tags where HTML markup prevails, but couldn't ellipsis ( or ...) be used to indicate 'stuff left out but it is noise rather than critical'? Commented Dec 12, 2017 at 6:50
  • 2
    @Lauraducky It's not about how smart I am, it's about the fact that the lack of a complete program tends to be a strong signal that the problem isn't even with the code shown, and that it's often hard to decipher exactly where this code fits into the program or how it gets called. I've left plenty of comments proving that the code in a question doesn't have the problem mentioning in the question, and vote-to-close countless more where there simply wasn't enough code to understand what's happening in the complete program. Commented Dec 12, 2017 at 6:55
  • 5
    "no wonder people give in eventually" -- no argument from me there. The entire Stack Overflow experience often feels like an exercise in futility. It attracts both the best and the worst of the programming community, and unfortunately, there's much more of the latter. But as is so often pointed out here on Meta (correctly, IMHO) if you feel like giving in, it's time to take a break. Harder to do for a person posting a question, but it also should be easier for that person to resist badgering from the uneducated, because they don't (shouldn't) have to deal with it as often. Commented Dec 12, 2017 at 7:04
  • 3
    Yeah, and worse still when that badgering translates into close and delete votes.
    – BoltClock Mod
    Commented Dec 12, 2017 at 7:08
  • 1
    @Mr Lister: Yeah, they were saying the missing html and body tags were errors, when they in fact weren't and the real errors were insignificant. That's what I meant by incomplete - their claims that the "required" tags were "missing", exactly what I'm taking issue with.
    – BoltClock Mod
    Commented Dec 12, 2017 at 7:27
  • 2
    It just needs a bit of understanding on all sides. If, say, just an event-handler method is presented, I would expect that the OP has verified that the method actually gets executed, (eg. breakpoint on first line fires), event arguments are valid, the values on any relevant class/instance vars are listed and there is as much detail of the actual problem and debugging info given as reasonably possible. If it can be confidently demonstrated that the other 5000 lines of the project are irrelevant, fine:) Commented Dec 12, 2017 at 8:34
  • 3
    The W3C's own validator claims that both the missing title and the missing alt are errors. Therefore you shouldn't be complaining when people say they are missing.
    – JeremyP
    Commented Dec 12, 2017 at 10:24
  • 2
    @JeremyP: I think you misread. People are incorrectly saying that the missing html and body tags are making the page invalid. I'm saying that the missing title element and alt attribute are the only errors on the page, and, more importantly, those errors have no impact on rendering and can safely be ignored for the purposes of that particular question.
    – BoltClock Mod
    Commented Dec 12, 2017 at 12:33
  • 4
    "MCVE" has become "linguistically overextended", like "Minimal understanding" before it, and for the same reason: Since it's one of the very few tools we have to effectively deal with crap questions, it gets widely applied. Glaring in frustration at the latest half-dozen offers of paid-for homework solutions, it's very easy to not un-squint and realize that a brief question, for once, actually is a complete and interesting programming problem requiring actual expertise to answer.
    – jscs
    Commented Dec 12, 2017 at 13:27
  • 4
    @Walfrat: Yeah, so the problem boils down to, "Should code in a question cater to popular misconceptions among non-experts?"
    – BoltClock Mod
    Commented Dec 12, 2017 at 13:43
  • 4
    @HostileFork: I'd considered titling this post "Should an HTML MCVE..." - perhaps I should have. It does seem to vary depending on the tag (and its audience).
    – BoltClock Mod
    Commented Dec 12, 2017 at 15:51

10 Answers 10

29

If the code runs just fine without it

Including it seems more like best practices about code than best practices about questions.

Trying to enforce best practices in code on Stack Overflow seems like an exercise in futility (I mean, we do leave comments pointing out standard naming conventions, for example, but commenting is about where it ends), so with or without it works.

If it is required to make the code run, but obviously so

Like a surrounding class for methods in Java or some standard includes.

Pros to including boilerplate:

  • There's no misunderstanding about whether the boilerplate was included, or whether there was some unexpected variation in the boilerplate which was causing the issue.

  • What is and isn't boilerplate is subjective - to one person nothing might be boilerplate, to another it might be strictly omitting something like importing from a standard library, to another it might be posting only the relevant function (which could very well exclude the problematic code).

    Including boilerplate gives consistency and avoids disagreements about whether or not something is boilerplate (which is especially relevant if the thing is not boilerplate).

  • The code (and possible fixes) is easier to test by others (which leads to faster and better help for the asker, and less frustration for the answerers and commenters).

Cons to including boilerplate:

  • A few more lines of code.

Based on this it seems like we should include boilerplate.

Although it might depend on exactly how many lines we're talking about. If its length greatly exceeds that of the non-boilerplate code, that would be a strong argument to not include it (although I'm not sure how many languages exist where a minimal example will have that much boilerplate).

But that's not to say we should downvote or close something where only unambiguous code is omitted and it's clear how to reproduce it and it's easy to do so.

7
  • "...we should include boilerplate." This could become very tedious. For example what about including a makefile. Or information about the exact version of the compiler/VM/... used. All compiler flags would be nice too. Or all installed Python packages. The output of pip freeze would be essential for every Python snippet. Environment variables. Should be there. Otherwise we would never be completely consistent. Commented Dec 12, 2017 at 20:43
  • 2
    @Trilarion I was mostly talking about code that appears in your MCVE file. Sometimes compiler version, makefile, installed packages, etc. would be required to reproduce (and in that case asking for them and voting to close if they weren't included is appropriate), but, most of the time, they're not (although it usually doesn't hurt to test in a different environment to find out whether the question is dependent on those things). This could also fall under "If its length greatly exceeds that of the non-boilerplate code". Commented Dec 13, 2017 at 8:34
  • I see. However, there is nothing special about the MCVE file. You basically make a very good case in your comment to leave out all the things of it that most of the time don't make a difference or can easily be guessed. A make file is no more or less part of a MCVE than any line of code I would argue. It brings us from the clear realm of including everything to the muddy waters of providing sufficient code context. In practice, I would say that questioners on SO (and everywhere else) provide not enough context, so asking for more is always a good idea. That's why I agree with this answer. Commented Dec 13, 2017 at 9:28
  • 3
    @Trilarion I can reproduce almost all SO-suitable problems without a makefile, doing a command-line compile. So to make your problem a MCVE ... you should have eliminated the makefile as a possible source of errors. Makefiles generate a command -- to be minimal and complete, just mention the command it runs to build your code and demonstrate the problem. The number of times I've looked at a SO problem and the problem has been in the omitted code is far larger than the number of times I've bemoaned truly minimal boilerplate. Commented Dec 14, 2017 at 15:24
  • @Yakk Okay. Then you are in the camp of only a certain amount of boilerplate. If there is no answer yet in this direction, you could write one. Commented Dec 14, 2017 at 20:24
  • Boilerplate is boilerplate for a reason. The problem comes when the "boilerplate" the OP is using differs from the boilerplate that everyone else is assuming they are using. So if the boilerplate is truly boilerplate, it is irrelevant, but if it isn't boilerplate then it is relevant. The only way for us to know if the OP's boilerplate is in-fact boilerplate is for them to include it.
    – user4639281
    Commented Jan 26, 2018 at 16:54
  • I'm a big fan of what Jon Skeet describes in his "asking the perfect question". In an ideal world, an MCVE can be copy-pasted into a text file and complied/ran.
    – mbrig
    Commented Jan 26, 2018 at 17:04
16

Clearly you asked this with an answer in mind. (i.e. no). I think that answer is fairly self-evident, so what would be really useful here would be hearing from someone who holds the opposite view about their reasons. I can't be that person, because I happen to agree with the answer you want, so I'm just going to lay out a case for it.

There are two reasons we ask for MCVEs:

  • Allow potential answerers with expertise in the topic to easily reproduce the problem (I mean, pretty much copy-and-paste levels of "easily", perhaps omitting boilerplate that any topic expert would know to fill in)
  • Give the asker and answerers an easy (roughly as above) way to check whether a proposed fix actually works

As far as I'm concerned, this is all an MCVE has to do. It's a throwaway code sample used for a one-off demonstration; it doesn't have to be syntactically correct or well-formed or adhere to coding conventions or anything else, except to the extent necessary to fulfill the two purposes above. It does have to include whatever is necessary to reproduce the problem, but anything beyond the minimum amount of code (or perhaps minimum complexity of code - let's not start golfing our MCVEs) required to do that makes it more difficult for readers to understand, even if slightly so, and is better avoided.

In particular, I'd say responses along the lines of "please provide the complete code sample" should be reserved for when the given code is insufficient to reproduce the problem, and insufficient in a way that really needs more input from the poster - I'm not talking about just omitting standard boilerplate, which a topic expert would be able to add themselves.

By saying this I don't want to imply that we should hassle posters about wringing every last bit of unnecessary complexity out of their code samples. Sometimes a sample that's a few lines more than minimal is pretty much just as readable as one that is minimal, and in that case it's no problem. E.g. if the asker had included a couple lines of boilerplate markup in the original question, I wouldn't care enough to make them take it out. But adding boilerplate is certainly no better than removing it (and probably worse), so I certainly don't think it's worth the fuss of adding it in.

6
  • 1
    Yes, that's my intention. I'm hoping to hear from others with differing views on this. I'm most specifically taking issue with people who claim that the missing boilerplate is the source of the problem when it isn't, but in general I'm looking to hear what sort of expectations folks have about MCVEs and what folks think is reasonable or otherwise.
    – BoltClock Mod
    Commented Dec 12, 2017 at 7:19
  • Yeah, I figured it would at least be useful to have our view represented. But I do also hope to hear from others with the opposite view.
    – David Z
    Commented Dec 12, 2017 at 7:19
  • Indeed, you pretty much spoke my mind on this.
    – BoltClock Mod
    Commented Dec 12, 2017 at 7:20
  • 1
    I'm in two minds about this one. First of all, I have seen many, many examples where people post only a few lines of code, and the code doesn't reproduce the problem. So what were they thinking? On the other hand, I have seen people pasting their complete HTML page in a snippet, and saying they can't cut it down to an MCVE because they don't know where the error is.
    – Mr Lister
    Commented Dec 12, 2017 at 7:27
  • 1
    I guess my point is that there should be a compromise between minimal and complete, which is not always easy to achieve.
    – Mr Lister
    Commented Dec 12, 2017 at 7:29
  • 7
    @MrLister If they can't cut it down because they don't know where the error is, whether the post too much or too little, I don't believe they can ask a question appropriate for Stack Overflow. Commented Dec 12, 2017 at 7:52
14

All snippets are complete, but some snippets are more complete than others.

tl;dr: KEEP YOUR BOILERPLATE OUT OF THE QUESTION. I can do that myself.


What you've stumbled upon is the Catch-22 of MCVE: some snippets can neither be minimal nor complete to satisfy noisy parties.

The main issue is one of, well, duckspeak.

We pontificate so much about having executable examples that it's almost a scapegoat anymore to demand an MCVE from an otherwise perfectly answerable question. I've noticed it as a trend more and more to demand that the OP do even more work to ask their question when, in reality, it doesn't really need that; the code they present is understandable by anyone who is versed in the language, or complete enough that an answer can be cobbled together and be serviceable for what the OP is asking.

The second issue is basically the community rolling with the mob. If I've said it once, I've said it a thousand times by now: the mob can be wrong. If you see ten people demand an MCVE on similar looking questions, you may think that it's okay to do that to every question, but there's a fine balance to strike here; a question need only provide the raw essence of what the OP was struggling with to begin with in order for us to make an answer of it.

The third issue (and elephant in the room) is really what MCVE was meant to address to begin with. We don't want to have someone post a homework assignment here with literally no effort, nor do we want someone to post their entire project here with no actual question besides, "It's broken. Help?" As I said earlier, we use this kind of as a scapegoat to put unnecessary onus on the OP to make them do mostly unnecessary work.

There's a balance to strike. Again, we don't want to field questions with just a question statement and no code/effort. We don't want to field questions with all code and no debugging effort. We want to meet in the middle here.

So...to your question:

Where is the line drawn?

If you can run it, and the code sufficiently illustrates the actual problem, then that is enough.

Keep your boilerplate out of the question. I can generate that myself.

2
  • 1
    Spot on. What I would have written instead of a stupid comment if I'd had time.
    – jscs
    Commented Dec 12, 2017 at 23:02
  • 1
    Took the words right out of my mouth... no not really but you spoke my mind, that's for sure.
    – BoltClock Mod
    Commented Dec 13, 2017 at 4:28
9

I think you mix up two things in your question. One is the issue of whether a single img tag constitutes a valid webpage and a valid MCVE. I have no idea, is not my tag. If it does, this is a non-issue. Educate the general public about the fact that it already is an MCVE. Nothing to see here, move along.


Assuming the more interesting case, where it isn't well-formed html, and doesn't constitute an MCVE technically... is the boilerplate code really necessary?

Yes

I'd argue it is. For you as the one writing the answer it might be blindingly obvious, which parts where necessary for you to spot the issue. I think we should assume the OP did not have that insight. After all he came here asking that question, it's safe to assume he is missing a vital piece of information. The OP should build that MCVE anyway. For their sake. Because it might solve the issue before even asking the question. So actually posting it in full is zero extra effort. So the OP already has this MCVE siting in their clipboard, has no idea which part of it is causing their problem... and yet, we are ok with them leaving out random parts, they guess are not the problem? That sounds stupid. We are losing good information that was already available. A full MCVE is a full MCVE because it's useful.

In your example, assuming the boilerplate were technically necessary, how would the OP know the missing title and body did not change their result? Well, only by already having it and running it. So why do the extra work of deleting that information, when you already have it in full? Doesn't make sense. Just paste it into the post.

8
  • I have no objection to providing a more complete sample - after all, whether or not the optional tags are there makes no difference, so either way goes. Except providing a sample that's too complete runs the risk of the question getting closed and downvoted anyway because some other people think there is too much fluff. It seems that you can't win either way and it really all depends on who sees your question, more than how much code you provide.
    – BoltClock Mod
    Commented Dec 12, 2017 at 15:37
  • "I think you mix up two things in your question" - Maybe it's clearer to me because I already know HTML, but I don't think BoltClock is mixing up anything; I think his question is pretty clear that <html> tags are not syntactically required. (That's not quite the same thing as a single img tag being a valid webpage; a doctype and a <title> are technically required too, unless the page is being sent as the body of an email, which is a special case in the HTML spec where the title can be inferred from the subject line. But adding <html> doesn't make the document any more valid.)
    – Mark Amery
    Commented Dec 12, 2017 at 15:38
  • As such, the majority of this answer is addressing a case that isn't in fact true, and subtly missing the point of the question BoltClock was trying to ask. The only part of this answer that speaks to the true case is "this is a non-issue. Educate the general public about the fact that it already is an MCVE. Nothing to see here, move along."
    – Mark Amery
    Commented Dec 12, 2017 at 15:40
  • 3
    @MarkAmery As I said, if what was posted in fact was an MCVE, then there is nothing to discuss here. People were wrong on the internet. That happens :)
    – nvoigt
    Commented Dec 12, 2017 at 15:40
  • 1
    @BoltClock That some people think it's too much and other people think it's not enough in the same post has never happened to me in the tags I visit. With a programming language, I'm happy to take something that's so complete I can paste it and it compiles. That rarely works in under 20 lines, so the thought that 5 lines of markup might be "too much fluff" is kinda alien to me. I suspect it's very localized to HTML based on the fact that is was designed so forgiving you can basically ignore most rules and still come out with a page that will render in some browser.
    – nvoigt
    Commented Dec 12, 2017 at 15:45
  • No, probably not in the same post, but I mean the same few lines of code (not necessarily html and body but some other tags) in principle would elicit completely different reactions in separate questions.
    – BoltClock Mod
    Commented Dec 12, 2017 at 15:46
  • 2
    @BoltClock I suspect we might be better off with a canonical "What is required for an HTML MCVE" meta post, that you can link whenever the question pops up whether it's the right amount of markup for an MCVE. I haven't seen that behavior in other tags. For example, I have never seen anyone being criticized for posting the main function definition, though technically it's the same boilerplate in all compiled languages.
    – nvoigt
    Commented Dec 12, 2017 at 15:58
  • @nvoigt: I haven’t seen anyone complaining about the missing main boilerplate either. For most tags I’ve seen, there seems to be the convention that anything that can be inferred by the reader easily, can be omitted.
    – Holger
    Commented Dec 12, 2017 at 16:16
8

Whether or not some code is "boilerplate" can only be decided with certainty once the answer to the problem is known. Of course some expertise helps creating code that is free of "boilerplate" code and to judge whether some part is likely to be related to the problem or not.
Most askers here do not have that level of expertise and what is more, most readers don't either. So there is no reason whatsoever not to provide a MCVE.

Once a MCVE is created and some problem can be reproduced, one may surely find an example which is even more minimal, still verifiable and complete. So the code that can be removed is possibly "boilerplate". However mind the sentence

Minimal does not mean terse – don't sacrifice communication to brevity.

from the SO MCVE page. So including commonly used tags in a code, even if strictly not required is not a bad thing to do.

While you may notify people about the fact that this part of the code is not required, one should keep in mind that including some "boilerplate" may actually help people understand the issue.

Looking at the code from the question the part which uses <html> and <body> is for sure much more understandable to people. If a question is more understandable, it is most likely much more useful to the overall community. Hence I would argue that including this boilerplate here is indeed a good thing to do.

1
  • That's what bothers me: the fact that more readers don't know better. I expect readers - potential answerers - to have the expertise to understand whether the snippets are complete or if they're actually missing something critical after all. I shouldn't have to cater to those who don't know.
    – BoltClock Mod
    Commented Dec 13, 2017 at 4:31
6

This isn't an example of boilerplate.

The documents the OP tested and was wondering about where actually complete. Changing those documents to include extra tags is neither minimal nor does it complete them.

The correct response to those requests is to edit into the question the word exact or complete, as in:

When I render exactly this complete HTML file:

<!DOCTYPE html>
<img style="width: 100%; height: 100%;" src="image.jpg">

and this complete HTML file:

<img style="width: 100%; height: 100%;" src="image.jpg">

in browser X I get symptom Z.

Errors in boilerplate can cause errors.

If your language actually requires verbose boilerplate (as some do), one way you can mitigate it is to include what you believe to be the relevant part, and provide a link to a live web compiler with absolutely minimal boilerplate added.

This seemingly violates the "questions should stand alone" and links should augment, but I think actual boilerplate is an augment (if a very useful one).

It satisfies the "answerers need to be able to easily reproduce the problem" part of MCVE. If the boilerplate truly is minimal and mundane and absolutely standard, the part in the question is enough to reconstruct it (with work), while at the hottest time in the question's lifetime answerers can easily play with the code in question.

And answerers can verify that the boilerplate is truly boilerplate at least while the link works.

As an alternative, you can add your boilerplate as a footnote to your question. You highlight the important part, and people are capable of scrolling past the boilerplate at the bottom.


I, as an answerer, have been bothered far more often because a code snippet is missing key components than from truly minimal boilerplate added.

Missing components both lead to the error being in a choice made in the missing components, and because it adds to difficulty of reproducing the error for answerers.

If you don't understand what caused your error, guaranteeing that you understand everything that could have caused the error is questionable.

2
  • 1
    This. I think the requests for a "real" MCVE in comments stems from the fact that 9 out of 10 (or 99 out of 100) questions are posted by copying some code from an actual project and removing what the asker deems important, without verifying that the posted snippet still reproduces the same problem. In this case, the requests should be ignored, and could be prevented by the word "exactly" you propose.
    – CodeCaster
    Commented Dec 14, 2017 at 15:46
  • I like this answer. Make it absolutely clear that the snippets are complete (assuming it is true) - by stating it explicitly.
    – BoltClock Mod
    Commented Dec 15, 2017 at 3:23
1

What is a MCVE for?

A MCVE is a Minimal Complete Verifiable Example.

The Complete part matters. If a snippet is incomplete, then two different users may complete it in two different ways and get different results; this will mean different answers, and possibly answers that do not match the OP's experience to start with.

So, yes, a MCVE should always be Complete.

Fluff, fluff, and fluff

On the other hand, should it be complete in the question, seems fairly debatable.

For example, in the Rust tag it's fairly common to see a snippet without fluff (no imports, no main), and then a link to the Rust playground containing the full-blown snippet.

It seems to me the best of both worlds:

  • the question is focused, allowing readers to immediately identify what it is about,
  • yet the link to the playground provides a ready-made canvas to start tweaking the code.

The only problem, of course, is that should the link go stale, then the snippet will be missing the exact list of imports. For standard items, it should be evident (if annoying), but for other libraries it might be more complicated.

YMMV?

2
  • 3
    You're missing the point of the question. Boltclock isn't talking about askers omitting required code like imports. He's talking about omitting bits of optional syntax that aren't syntactically required and make no difference to the meaning of the code, but which some readers wrongly believe are syntactically required.
    – Mark Amery
    Commented Dec 12, 2017 at 12:24
  • 3
    @MarkAmery: I'm not missing it so much as making the more general statement (or at least trying to) that I support the idea of focusing the question on the specifics, eliding the fluff (whatever it may be) but still providing the full content for easy reproduction. I took the example of "imports" because that's what I know, but I envisioned fluff to include any bit of code which is not required to understand the question, including optional bits of syntax. I'm keen on suggestions to make this clearer. Commented Dec 12, 2017 at 15:31
-2

Since there is no accepted answer to this question yet, let's play devil's advocate and answer the question: "does including the body start tag have any effect?"

The OP says no, it doesn't have any effect, but in reality, it does sometimes.

Take these two HTML documents. One has all the optional tags

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<style>body {white-space:pre}</style>
</head>
<body>
<img src="https://placehold.it/100x100" alt="">
</body>
</html>

and one has the optional tags removed

<!DOCTYPE html>
<title>Test</title>
<style>body {white-space:pre}</style>
<img src="https://placehold.it/100x100" alt="">

These are both valid HTML5 sources which make it through the W3C validator without errors or warnings. Yet they behave differently; just paste these sources into two different HTML files and compare them in your browser.
The conclusion should be clear: if you omit the boilerplate, make absolutely sure that omitting it has no effect.

8
  • 1
    This example in no way supports the conclusion that <html>/<body>/<head> should be included in questions. The fact that it's possible - by going out of your way to change the meaning of whitespace from the default - to make inclusion of these tags have some effect on the semantics of the document is not the same thing as them being required by spec or being necessary to reproduce (or in any way relevant to) the particular problem that somebody is asking about.
    – Mark Amery
    Commented Jan 26, 2018 at 13:26
  • @MarkAmery I never said that the tags were required by the specs; that wasn't the particular question I was addressing. Also you missed the part where I was playing devil's advocate.
    – Mr Lister
    Commented Jan 26, 2018 at 14:05
  • 1
    Sure, but the question you are answering is one that nobody asked and doesn't help to answer the one that BoltClock did.
    – Mark Amery
    Commented Jan 26, 2018 at 14:18
  • As I stated in the question: "A third [commenter] mentioned that the tags are indeed required under certain circumstances — except this wasn't one of them" The question is whether or not they should be edited in after-the-fact when it's clear that they aren't going to have any effect (or, in the case of pure HTML questions, whatever side effects they may have on layout aren't going to be relevant because CSS simply isn't involved).
    – BoltClock Mod
    Commented Jan 26, 2018 at 14:45
  • Having said that, unfortunately it's still not clear to me what the conclusion is. if the conclusion is that optional tags should be included anyway as a safety net, I'm fine with that. But when what you've provided does meet all the requirements of an MCVE, and then you get asked to pollute it with stuff that you know (and you'd expect potential answerers to know, too) simply isn't relevant, you start to realize why some askers don't bother putting time and effort into the M.
    – BoltClock Mod
    Commented Jan 26, 2018 at 14:50
  • @BoltClock I was just trying to say that in some circumstances, you can have differences that are not clear at first sight. Yes, it did take extra CSS to highlight the differences in this case, but that doesn't mean the differences aren't relevant.
    – Mr Lister
    Commented Jan 26, 2018 at 16:29
  • @MrLister What's your point? The fact that differences can exist doesn't mean that they do exist in any particular case, and even if they do, the fact that the HTML would have a slightly different meaning with the tags included doesn't mean that the tags should be included. The HTML will have different semantics too if you put <p>Hello, I am a random extra element included for shits and giggles</p> at the bottom, but that doesn't mean you should do that on every post. Why don't you tell us what your conclusion is instead of that it "should be clear", because neither of us have a clue.
    – Mark Amery
    Commented Jan 26, 2018 at 16:35
  • @Mr Lister: Neither does it always mean that they are. It depends entirely on the code. It's not all or nothing. But I do understand where you're coming from regarding things that aren't clear at first sight.
    – BoltClock Mod
    Commented Jan 26, 2018 at 16:49
-3

Should an MCVE include boilerplate that's not required just because people incorrectly think it is?

As a matter of question-asking strategy, I'd say that the answer is probably "yes". Under the stipulated circumstances, including the extra bits is more likely to get a useful answer, faster, and it reduces the risk of the question being (incorrectly) closed for not presenting an MCVE. But if you end up unexpectedly running into poorly-informed community members who do not recognize an example's completeness then it probably serves the community better to challenge their objections than to give in to them. To a point, anyway.

Inasmuch as the question seems really to be aimed at whether the community should require such boilerplate, however, I'd say the answer is "certainly not". Including any code beyond that required to establish the context and reproduce the problem makes an example non-minimal, and doesn't help anyone.

Moreover, including additional code may change the meaning of the question. Take the example that we started with. If the lack of <title> elements and alt tags is characteristic of the situation the OP wants to know about, then

  1. it behooves the OP to be clear about that, but also
  2. it is counterproductive for the community to refuse to answer the question on the basis that those are missing.

Nevertheless, "different user agents may handle invalid HTML differently" is then a plausible answer (regardless of whether it does a good job of explaining the observed behavioral difference).

On the other hand, if the document invalidity arising from absence of those syntactic elements is not characteristic of the problem, then the omission clouds the issue. Although the code is shorter, it is incomplete. Inasmuch as the omission introduces concerns that are not actually relevant to the question, one could argue that in a conceptual sense, such an example is not minimal, either.

-3

I definitely think that boilerplate should be included. Quite often when I help someone, I copy-paste the code and run it. Including the boilerplate saves me from having to write that on my own.

Another big benefit is that it makes it sure for everyone that it certainly IS an MCVE. Let's take a silly example. Consider someone asking why this C-code does not print its own name:

main.c:

printf("%s\n", argv[0]); 

That should work. Right? But here is the complete main.c:

int main(int argv, char ** argc) {
    printf("%s\n", argv[0]); 
}

I switched the names of argc and argv. But many would consider this boilerplate.

1
  • 1
    I disagree wholeheartedly. Method signatures and declarations are definitely not boilerplate.
    – Makoto
    Commented Dec 24, 2017 at 17:13

You must log in to answer this question.

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