Occasionally I write larger scripts (sometimes far over 100 lines of code) to answer questions on the site.
If I believe they are useful for more people or in more cases than the specific question is about or if I am going to maintain and update it every now and then, I prefer to put the whole code into a GitHub repository and link that in my answer instead of dumping the code there.
Of course the answer still contains detailed explanation and instructions to download it from GitHub and how to use it.
What do you think of outsourcing big enough scripts to GitHub?
Here are the pro and con arguments I can come up with, trying to ignore my personal opinion in favour of using using GitHub:
- easier to read, people don't "TL;DR" (do not read it because it's too long)
- consumes less space, other answers below have a higher chance to also get read (people do not like to scroll down too far)
easier to get code:
- you can download the whole repository as Zip archive or download single files of it
- no need to copy large snippets out of code windows in the answer, paste them in a text editor and save them under a specific name
- if you have set up
gitand know how to use it, you can simply clone the repository to your local machine and even have all file permissions preserved.
- the author can have a local git repository, edit it with their preferred IDE and directly commit and push the changes to GitHub. No need to look up the answer and copy/paste and format the code.
- no risk of forgetting to update the answer on code changes
- code is not stored duplicated
- GitHub allows adding any number of files, including further documentation, examples or more script files
- GitHub allows controlled contributions from other people
better usability for newbies
Imagine you are a rather new user who simply wants stuff to work and does not care too much about the details. You only have a very basic IT knowledge and just want something to double-click, not its entire code - I guess this is the average Ask Ubuntu visitor.
Now from the perspective of this user, compare an answer saying
"I made a script for this problem and published it on GitHub here (→link). Simply download this (→link) file and make it executable (
chmodetc.), then you can run it."
with another one like
"I made a script for this problem. Simply copy the code below, open your favourite plain text editor, paste it and save the file as xy. Then make it executable using
chmodetc. and you can run it.
Huge wall of code which you don't understand at all
- Answer does no longer directly contain all relevant information, one could argue that it is a link-only answer.
- The link might die and the script may no longer be found. That's the main reason why link-only answers are not allowed.
- It requires an additional click to get the needed information.
- You need to leave the site to get the needed information.
You see that I'm personally very much in favour of using GitHub to store long scripts, but what is the opinion of the community? Please share your thoughts.