When asking for help with a coding problem it is important to do as much as possible to make certain your audience is able to immediately understand the issue and assist with a solution. Whether it be via forum or by contacting technical support there are things you can do to ensure that your query is given the necessary attention and is properly understood.
Below we describe methods which can help ensure that your code is sufficiently short and properly self-contained.
Leave out the unnecessary parts of your code
Remove code that does not contribute to the issue. This serves two purposes:
- it makes it easier for the people reviewing your code to get to the actual problem
- it oftentimes is a good troubleshooting step that may help you identify the issue yourself
For example, if you were having a problem with your Plot command:
one approach would be to try to remove the options one at a time until the issue is no longer present. This will help indicate which option could be causing the problems, and can help focus the issue without the rest of the “clutter”.
Minimize the content that the example relies on
Try and minimize any data the issue relies on. For example, if your issue relies on data from a larger CSV file, see if you can reproduce the problem with a portion of the data. Instead of expecting someone else to obtain and import the data, for example,
just provide a few values they can use to reproduce the problem:
Similarly, if your results rely on long computations, see if you can remove these computations from the issue. Let’s say you have a Plot command that isn’t working right, but relies on an integral that takes a few minutes to solve. Instead of sharing the following:
Send the output of the already evaluated integral directly, to remove that unnecessary information from the request (assuming the
Integrate command above eventually evaluates to
Remove unnecessary formatting
Get rid of formatting, and try to present the issue in one-dimensional ASCII text. For example, if you like to work with integrals in their TraditionalForm,
try converting the code to its InputForm before sharing:
You can convert a cell to its InputForm by right clicking (Control-click on Mac) on the relevant cell’s bracket and choosing item Convert To ► InputForm.
Similarly, if your code contains non-ASCII characters like Θ or π, it usually does not copy well into ASCII environments:
This can easily be rewritten with more “standard” characters for easier-to-read code:
Ensure others can run your code without issue
Verify that others can run your minimal example. Just before you send your code, quit and then restart your Wolfram Language session, and then immediately rerun the code you plan to send. This tests that your code is not mistakenly relying on any variables or symbols that need to be included.
For example, sending the following Plot command without the definition for
fn would be difficult for someone to troubleshoot:
Share your content effectively
If your example can easily be represented in a few lines and has no tricky formatting we would recommend pasting it in the body of the post or email. If the code is longer or more involved we would recommend sending it within a Notebook as this may better preserve the content.