-5

MREs are great, but often it takes more than one isolated piece of code to reproduce an issue. It seems the in-built MRE tool (the one with the "Run this code snippet" button) can only do so much when it is the case.

How can I create an MRE that involves multiple interconnected files? Is referencing CodePen and similar sites acceptable in these kinds of situations (though, I'm not sure CodePen is helpful with backend projects)? It can involve interactions with databases too which complicates it even further. Can I get away with not including runnable MREs in such cases?

6

3 Answers 3

20

Is referencing Codepen and similar sites acceptable in these kinds of situations

Questions should be self-contained. Any links in the question should be supplementary, the question should not rely on visiting the link. The off-site resource may change, or be inaccessible for any reason*.

Add any relevant code to the question. If there are multiple files, add them to the question as different code blocks

first_file.xyz
// content of first file
second_file.xyz
// content of second file

And so on.

Very important to stress: make sure that the multiple files are indeed needed. Because one of the key parts of a good example is being minimal. Only include the code needed. And if having multiple files is irrelevant, then combine them into a single code block or (if possible) a runnable snippet.


* On a personal note, Codepen does not work for me because of some addons I have on my browser. And I frankly cannot be bothered to fiddle around to make it work because I never really use it. If that is the only way to see the code, I will pass.

1
  • Re "make sure that the multiple files are indeed needed": That can be read the wrong way. Apr 10, 2023 at 17:50
11

The defacto response is that multiple files isn't "minimal", but I wanted to think about this a bit differently.

What we really care about is that there's just enough code to reproduce your specific problem. Your role as an asker should be to trim down the question you're asking to only contain the essentials which - by itself - has enough info to determine what your specific problem is.

If you have to have multiple files (like you're building a website snippet, for instance), you should be sure that there's enough snippets to comprise the whole problem (HTML, CSS, JS/TS). If not, omit where necessary just to narrow your scope.

6

Since there seems to be some ongoing confusion on this point in your more recent Meta, and it does not seem to have been addressed here yet:

It seems the in-built MRE tool (the one with the "Run this code snippet" button)

This is not "the in-built MRE tool".

It is not necessary for any question to use this feature, in order to provide an MRE.

It is only a convenience for demonstrating examples in the browser, which works only for JavaScript/HTML/CSS examples (because that is what the browser environment supports out-of-box).


To reiterate: the code for an MRE, regardless of language, consists of

  • the contents of source files needed to cause the problem, with proper formatting;

  • if there is more than one file, some instructions about how to name them and organize them in the file system.

We should have full steps to reproduce - hence, the file names/folder structure, if applicable. The steps to reproduce should be as simple as possible: so, hard-code the inputs where you can, and remove parts of the calculation that are not relevant to causing the problem. The idea is that we should be able to copy and paste the code into the appropriate files and folder structure, without adding or changing anything, and see the exact problem, directly.

All of this is already documented in the site help section. Like it says, all emphasis mine:

Use individual code blocks for each file or snippet you include. Provide a description for the purpose of each block.... If you are using HTML, CSS, and/or JavaScript, you can use Stack Snippets to include [a]runnable snippet instead of just a static code block.

2
  • I also noticed the characterisation "the in-built MRE tool" at the time, but is it totally wrong? The tag wiki says (my emphasis) "Stack Snippets ... are an onsite alternative to external sources like JSFiddle and are meant to encourage users to provide a Minimal, Complete, and Verifiable example along with pertinent questions.". Apr 19, 2023 at 12:02
  • 5
    Encourage, not enable.
    – cafce25
    Apr 19, 2023 at 12:41

You must log in to answer this question.

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