7
\$\begingroup\$

I know my code doesn't have to be complete. However, in my specific case I have a project where I'd like to focus on performance improvements. Some optimizations are obvious, where others require analysing the code with the used resources.

Irrespective of my specific case my question can boil down to; I want to post the resources used in my project. To provide a complete question. How do I include resources for review?

\$\endgroup\$
0

3 Answers 3

7
\$\begingroup\$

Include links, embed images and where possible audio and videos

From the beginning of Winston's answer to Does my code example need to be compilable/runnable?:

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

From Simon's answer to Can I put my code on a third party site and link to the site in my question? (emphasis mine):

If your code is too long (doesn't fit within the 65 535 character limit for posts on Code Review), please select only the portions of the code where you are especially interested in getting reviewed. In such a case, you may add a link to a site where more of your code can be seen, but don't expect anyone here to review it.

For example, at the end of this question is the following text with a link to the text file from an external site:

If you want to run the algorithm yourself, then you need this grid.txt file.

Images can be embedded in a post. For more information see the Advanced Editing help section about Images.

For audio and video files, one option might be to embed them in a Runnable snippet though the files would still need to be hosted externally and would suffer from the possibility of link rot. Below is an example using sample code from the MDN documentation.

<div>From the MDN documentation for <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio"> <code>&lt;audio&gt;</code></a></div>
<figure>
  <figcaption>Listen to the T-Rex:</figcaption>
  <audio controls src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3
">
  </audio>
</figure>

<div>From the MDN documentation for <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video"> <code>&lt;video&gt;</code></a></div>
<video controls width="250">
  <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" type="video/webm" />

  <source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4" />
</video>

\$\endgroup\$
2
  • \$\begingroup\$ So ultimately, I think your answer is the correct one. However, I should mention that my application uses >100 images. Hence the performance improvements. Should I link to the folder repository of the images? Or should I literally embed them all? \$\endgroup\$ Sep 5, 2023 at 21:17
  • 1
    \$\begingroup\$ I would just add a link to them. If it gives satisfaction to embed ~2-3 then go ahead and do that. \$\endgroup\$ Sep 5, 2023 at 21:45
2
\$\begingroup\$

Expanding on the existing answer:

If your code depends on data, include the schema or an illustrative example of that data. For example use the newly supported tables to explain stuff:

Names of Columns
integer string float
some example values

And the number of rows

Or in the case you have ">100 images" that are all similar then embed some illustrative ones in the post to give an idea what you're working with. Obviously if it's just resources like icons or form backgrounds, then I wouldn't consider that data in the same way.

The aim is that your code can be reviewed on the site without clicking on any links, but if you need to execute the code then a link to a working demo on e.g. GitHub would be fine in addition. This extra effort benefits you, as if your post contains all the necessary context for review then you will get more answers. Cautious potential reviewers may be put off having to click external links, or may be on mobile unable to run your code anyway.

This often happens in the Excel and VBA tags where the code is dealing with a workbook. For me the ideal post would:

  • include all source code
  • include markdown tables to describe your data, or if it is not tabular then screenshots and descriptions
  • embed any other images etc that constitute examples of data
  • screenshot of the workbook before and after code runs since often formatting in the spreadsheet improves readability
  • link to a GitHub repo containing all exported code, and data files and a demo.xlam file with everything conveniently packaged

Now I can review the post on mobile or a work computer without leaving the site, or if it's very complex then download the demo at home and play around with that to figure out how it fits together.

\$\endgroup\$
1
  • \$\begingroup\$ Makes sense, I appreciate it! \$\endgroup\$ Sep 9, 2023 at 17:36
1
\$\begingroup\$

Use the techniques you'd use for your auto tests.

Often the best form of compression for stress-test inputs to programs is in the form of a program or script that generates the required quantity and shape of data.

I find it very helpful if the script has one or more command-line parameters for testing and debugging, as we can easily produce problem cases on demand, or tune the quantity of input to balance coverage with test duration.

\$\endgroup\$

You must log in to answer this question.

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