4

Given a user provides a textual representation of data he has in a file and wants to load and process in the code provided with his question.

Those who want to try out the code of an answer don't have the user's workload data in their local storage, so they must produce it, which is a potentially error-prone, or even harmful (imagine there's a file called test.csv in the directory where their thesis-to-be resides) thing.

Or, if the data is inlined as a string in the answer, and treated such by e.g. C++'s std::stringstream or python3's io.StringIO (python2's StringIO.StringIO), the answer's code is, for beginners, not trivially convertible for a processing of physical files.

Is there a consensual or known best-practice way to deal with such persistence issues arising when answering a question?

EDIT

example

This

with open('mycsvfile.csv', 'w', newline='') as f:
    for row in journal_entries:
        for innerRow in row["journalEntryItems"]:
            writer= csv.DictWriter(f, innerRow.keys())
            writer.writerow(innerRow)

is the users code; the data sample he provides is the big .json he gives as a string in his question. Of course, the user has that file on disk, but those who want to try an answer's code, don't.

So it needs somehow to be made available in an answer with code that processes that data.

My question is about that somehow.

21
  • 4
    Close voters, this does look like a legit meta-question, although it's quite hard to understand. Commented Nov 6, 2015 at 14:09
  • @FrédéricHamidi: What's difficult about it? How can I improve it? Commented Nov 6, 2015 at 14:10
  • The bullet point in your third paragraph looks like a formatting issue but remains understandable, however I don't understand your fourth paragraph at all. Could you elaborate on it? Commented Nov 6, 2015 at 14:12
  • @FrédéricHamidi: Thanks I tried to improve it. Commented Nov 6, 2015 at 14:18
  • @closeandownvoters If that has already been answered somewhere, pls tell me, and I will happily delete this question. Otherwise - that is daily business when answering questions, thus I'd say that this meta Q&A is exactly the right place to ask it - if not, where else? Commented Nov 6, 2015 at 14:27
  • 1
    This question should be re-opened. It's on-topic for meta.
    – Cerbrus
    Commented Nov 6, 2015 at 14:36
  • 2
    @Cerbrus I agreed that it's definitely on-topic. It's a bit unclear, so it might still be closed for that.
    – ryanyuyu
    Commented Nov 6, 2015 at 14:37
  • @Cerbrus I voted to close it as unclear because I cannot figure out what the heck it is asking. In my book, that some close-voters read it as off-topic for Meta is indication that they did not understand what the question is asking. I still see it as unclear, despite the edits.
    – Louis
    Commented Nov 6, 2015 at 14:48
  • 1
    I can't make heads or tails of it. This question desperately needs physical examples rather than a description of examples.
    – Gimby
    Commented Nov 6, 2015 at 14:53
  • 1
    I voted to re-open, because it was closed as "This question does not appear to be about Stack Overflow or the software that powers the Stack Exchange network", which would be incorrect.
    – Cerbrus
    Commented Nov 6, 2015 at 14:54
  • 1
    If I may distill this: a person has posted a question which assumes data on file, but we as prospective answerers don't have access to the file. If they post enough of the file to exhibit the behaviors that they're asking about, what's the issue with copying the file locally?
    – Makoto
    Commented Nov 6, 2015 at 15:11
  • 1
    @Gimby example added. Commented Nov 6, 2015 at 15:12
  • @Makoto: If I may distill your comment - you opt for delegating the task of creating the assets needed to run the code of an answer to those who want to run it. Do I get you right? Commented Nov 6, 2015 at 15:16
  • 1
    @decltype_auto: Well, where else are you going to get those assets? Either they're provided for us in the question (which the answer would then assume "correct behavior" with), or they're provided in the solution (which would be awkward, but still acceptable).
    – Makoto
    Commented Nov 6, 2015 at 15:20
  • @Makoto as I sketched it above, one can inline a string representation of data in the answer and mock file stream access by means like those mentioned above for C++ and python. One could also write that data to a tmpfile is sort-of setup section of the answer, and then re-open it for reading by the same means the user would have to use. Commented Nov 6, 2015 at 15:24

1 Answer 1

4

If the question does not specifically depend on the data, you can write a general answer that the OP or others can apply to fit their needs.

  • How do I load this (type of cvs) data into my code?
  • How do I manage (represent, decode, split) this data?

These questions don't necessarily require the specific or entire data set that the user mentions (and probably can be closed as duplicate questions).

If the question isn't a dupe, you can provide a couple of lines of sample data apart from your code, and let the user adapt your code to fit their needs.

test.csv

Patrick Stewart;Prince of Egypt, The (1998);Steve Martin
Steve Martin;Novocaine (2000);Kevin Bacon

    <code that shows how to load or process test data>

The point is that you can reduce the answer and/or data to a minimal example that focuses on the question.

Since the question likely isn't How do I inline this persistent data in my code?, there's no need to obscure the code with some form of inline data.

If the question is about how to solve a problem based on a set of data, you can write the answer in a way that that illustrates how the problem can be solved.

If the data itself is of critical significance, it's been archived somewhere. You can provide a link to the data. But the site itself is about providing answers to helpful questions, not about how to preserve the data that the question might use.

In terms of protecting users from inadvertent consequences of running code, you really can't protect someone who blindly runs code in their thesis project directory and doesn't happen to have a backup of their project.

If there are concerns about malicious code, you can down vote, comment, and/or flag the question.

Update

You've added this to your question:

Of course, the user has that file on disk, but those who want to try an answer's code, don't.

So it needs somehow to be made available in an answer with code that processes that data.

My question is about that somehow.

People come here looking for answers. They're generally not looking to test an answer's code. They're here to learn from and adapt the answer to fit their problem.

The purpose of the answer is to help others. While it may help the OP, that's not an answer's reason for existence.

The StackOverflow portion of an answer only needs to focus on the specific code that generally solves the problem. If you feel it is essential to also provide a complete working sample with data that others could download and run, you can host that code and data set elsewhere (such as a repository on GitHub), and include a link to it in your answer.

7
  • But if the code in question contains any open("filename") - like call, what then? If one doesn't make it fool-proof that the code will be run with valid input, then Murphy's law guarantees that it will go wrong. Commented Nov 6, 2015 at 15:40
  • @decltype_auto Is the question really about defensive coding? Is the user specifically asking how to handle invalid input? If not, you can comment that the user may want to check that the input is valid, instead of obscuring the answer with handling anything that could possibly go wrong.
    – user4151918
    Commented Nov 6, 2015 at 15:44
  • The question is not about defensive coding, but persistence. Commented Nov 6, 2015 at 15:56
  • 2
    Then provide a link to a specific question. Otherwise, as Makoto mentioned, the data was either included with the question (and doesn't need to be reproduced), or could be included with the answer. The answer should be more important than the data. Avoid unnecessarily obscuring the answer by including the (entire) data set in your answer.
    – user4151918
    Commented Nov 6, 2015 at 16:06
  • I would understand the topic is clear enough meanwhile. Commented Nov 6, 2015 at 17:11
  • And by btw - I appreciate advice, but mind your tone, pls. Issuing imperatives is inappropriate. Commented Nov 6, 2015 at 17:24
  • @decltype_auto Apologies! I actually appreciate and respect your intent to be thorough, and to invest more time in an answer :)
    – user4151918
    Commented Nov 6, 2015 at 18:06

You must log in to answer this question.

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