Detailed Recommendations for Code Reuse

Make sure you (or somebody else) can re-use your code to do the same exact thing you did. This section contains a simple checklist of recommendations for making your software more reusable. In this section contains a more in-depth explanation of each of these recommendations, with pointers to other relevant parts of this guide.

Repeatable Recommendations

At this stage, you might not even need to be able to open the code and read it, you just want to make sure you can re-run all the needed steps and obtain the same results you had.

Re-runnable recommendations

Make sure you (or others) can re-use it to do the thing you did, but with different data/different parameters

Portable Recommendations

Portability refers to the ability to transfer software to a new environment. This could refer to an identical (but not the same) machine, but it can also refer to a new hardware architecture, operating system and such. Both of these are important for software reuse.

Extendable and Modifiable Recommendations

Make sure others can build on your code to extend it and improve it.

Exercises

For the rest of the session today have a go at the following:

  1. Open a piece of code that you have been working on recently.
  2. Go through each of the points under the tabs. Think about whether your code adheres to each point (some points may be more relevant depending on the purpose of your code).
  3. Make a note of points you think could be applied to improve the reusability of your code.
  4. Choose one of those points and spend the rest of the time today implementing them to your code. Ask for help if you want.

Some ideas:

  • Put your code on GitHub. We can help if this is the first time you've used git and GitHub :-)
  • Go through a script that's a bit messy and try and write it in a more modular way with functions. Even just thinking about the logic and how you would break it down if you dont have time to write the functions themselves.
  • Add comments to your code. Think about how you would explain it to someone else.
  • Write a README file for your code. This could be a simple text file that explains what the code does, how to run it, and any dependencies it has.
  • Capture dependendencies, perhaps create a DESCRIPTION file with packages and versions used. Or do the exercise here.
  • Apply a linter to your code.