Cookbook package for tested one-liners and snippets

The recent discussion on package registration waiting periods and the merit of one-function packages got me thinking. I think stackoverflow shows that there is a demand for simple functions that solve problems that are quick to solve if you know how but can be tricky if you don’t. Or if you simply wish to not waste time on coming up with a solution and would like to copy-paste something that has been tested by someone else.

People don’t bother setting up packages for such functions in almost all cases, and it’s probably good that they don’t. But copy-pasting a random snippet off stackoverflow can be frustrating if it has been written for a previous version of Julia, or just doesn’t work quite right.

Here’s my idea: Set up a generic cookbook package or just a repo that everybody is free to PR to. This would not be intended as a dependency but as a collection of useful snippets. Submissions would have to adhere to certain constraints to keep them simple and copy-pasteable. Maybe just functions and macros but no types, for example. Things that work without any dependencies. Each function would have to have a clear docstring and a couple of tests. Maybe even a simple benchmark. All this could be automatically compiled with Documenter into a nice website.

The minor version would grow with each modification so people could refer to the version that they copied. This way, we could grow a higher-quality collection of helper functions that don’t merit dependencies but can still be trusted to work with some confidence. I think this could be quite valuable to have. I certainly have often wished to have something between github gists and a full package. Something with tests to show if it still works years later.

What do you think?


It sounds good.

I am not sure what you are referring to here, but a lot of questions on SA are simply about combining existing pieces, which is just part of programming.

Eg to make things concrete but not single out any actual SA question, a typical one is along the lines of “how do I find the largest odd number in an array?” (I paraphrased an actual SA question). A simple solution could be

largest_odd(v) = maximum(Iterators.filter(isodd, v))

Does this belong in a package? Possibly not, discovering it is actually more costly than writing it.

Cookbooks are a very good analogy here: if you learn a few basic principles of cooking (what reaction happens at which temperature, hydrophilic and hydrophobic amino acids, denaturation, etc), you can use cookbooks for inspiration, and compose your own dishes easily.

(Sorry if I misunderstood the question, in which case please clarify with examples.)

This also just reads like:

Or Fun One Liners

1 Like