2

If you're posting a question which requires an MVCE, should you include the import statements?

I feel like certain code becomes ambiguous if you don't include the imports, especially in Python.

4
  • 7
    Of course, you should post something that could be copy-pasted and run.
    – jonrsharpe
    Commented Jun 16, 2017 at 19:08
  • 2
    If you're thinking about arguments you might have seen to the contrary, I believe those users were talking about not including them in the answer to save space.
    – BSMP
    Commented Jun 16, 2017 at 19:48
  • @MikeMcCaughan questions are not answers
    – Matt
    Commented Jun 18, 2017 at 18:51
  • The answer is the same, because the underlying issue is the same; the need for posts (questions or answers) to be complete and verifiable. Commented Jun 18, 2017 at 20:10

1 Answer 1

7

If it's necessary to run your snippet of code, it's necessary to include in your MVCE. Otherwise, it's not "complete".

7
  • 4
    To add to that, I've seen a lot of cases on SO in which the imported namespace or library is imported incorrectly, and therefore used wrong, so including it saves a lot of time trying to find suspect issues elsewhere in the code when everything else is fine. Commented Jun 16, 2017 at 19:33
  • 2
    I'm not sure I agree with this. Can you imagine all C# posts including using statements?
    – user247702
    Commented Jun 16, 2017 at 19:55
  • @Stijn what is an MCVE if not Minimal, Complete and Verifiable?
    – user4639281
    Commented Jun 16, 2017 at 19:58
  • 1
    @TinyGiant I agree that it's not a true MCVE without import statements, but I'm not sure if we actually need to be that strict. It's rare for code to be unclear without import statements, at least for the tags I browse.
    – user247702
    Commented Jun 16, 2017 at 20:04
  • 2
    @Stijn: I will admit that, being in the Java space, I leverage IntelliJ for about 99% of the imports I care about. The 1% which I can't get are what should be provided to us; if they're using a custom Calendar class we need to know about that.
    – Makoto
    Commented Jun 16, 2017 at 20:07
  • I would agree with Makotos comment: I would omit obvious imports to core classes and only post imports to own or library classes.
    – Tom
    Commented Jun 16, 2017 at 20:32
  • 1
    @Stijn I know that one of the most common (simple) problems that Stack Overflow users face with JavaScript libraries is the libraries not being included properly, and most of the time we only get the code that leverages the libraries. I don't know if that is relative in other languages. Yeah you may use an IDE that takes care of all of that for you, but it is fairly common to see new programmers not leveraging such an IDE who may be including things improperly. I think that if you have an IDE which handles the includes for you, you should mention that in the question, otherwise include it.
    – user4639281
    Commented Jun 16, 2017 at 20:43

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