17
\$\begingroup\$

I'm thinking of posting a question here, but am unsure how I should do so. The question is about comparing the performance of a piece of pure Python code vs a hybrid Python/C++ piece of code, glued together with Boost Python.

Now, I could (probably) create a minimal working example (MWE), but it would be quite long, and would have to include at least two code files (a Python one and a C++) + a build script (I use scons). Since the question also includes data input, I might also have to write some additional code to create such data input.

So, some alternatives for how to post this question are

  1. Include all these files in my question, separated by markers.

  2. Point to a code repository (I use Bitbucket) which people can grab the complete code from, and just post the most relevant snippets in the answer.

  3. Just post the relevant snippet, which however is not compilable or runnable.

Opinions?

\$\endgroup\$

3 Answers 3

15
\$\begingroup\$

Post the relevant snippet, link to a code repository for those who want to actually run it.

Code is required to be in the question for a number of reasons:

  1. To prevent people from asking for reviews of huge projects
  2. To make it easier to see the code and thus get more reviewers
  3. To not depend on third-party hosting services
  4. To avoid confusion when the OP changes the code in the repository and suddenly the answers no longer apply to the linked code
  5. To ensure that the question contributes to the community, as all content posted to StackExchange sites is implicitly Creative Commons-licensed.

But linking to more code is encouraged. Just don't expect any reviews on it.

\$\endgroup\$
0
11
\$\begingroup\$

You'll get better answers if you post code that's runnable. Code that's runnable can be tested for bugs, timed for performance, stepped through in the debugger, and so on. For example, this detailed performance analysis and refactoring would not have been possible if the code had not been runnable.

If there's a graphical or other form of user interface, things stand out when interacting with the program that would be much harder to spot from the source code alone. For example, when reviewing this game I'd probably never have noticed that the jewels were falling upwards just from reading the source, but it was obvious as soon as I ran the game.

Even if you only want to post a small portion of your program, it's still well worth making the effort to reduce dependencies, provide stubs, or otherwise adjust the code so that it is easily runnable.

\$\endgroup\$
0
1
\$\begingroup\$

In principle the posted code doesn't need to be runnable or testable in the sense that we can just copy it and paste it in our IDE of choice. Posting only relevant code is acceptable if at least it is clear from the question what is expected to be reviewed.

But, there is IMO at least one exception of this "rule": If you post code of a class which is clearly shown as a class, meaning that for instance for C# you have posted a class including the classes body like

public class MyClass
{

}  

then all of the methods and properties which are used and are part of that class should have to be present in the code, because otherwise it is very hard for us reviewers to do our job. It is very hard to review code if e.g any second method which is called is missing.

If you post only the code of e.g. a method, then a reviewer expects that any method call inside the posted code where the method isn't posted will be irrelevant to that question. This is because the method which isn't shown doesn't live in the posted code.

\$\endgroup\$

You must log in to answer this question.

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