Snippets management

Robert Lehmann stargaming at gmail.com
Thu Nov 6 08:19:15 EST 2008


On Thu, 06 Nov 2008 05:23:25 -0600, Edwin wrote:
[snip]
> As I'm learning Python sometimes I look for different approaches to the
> same problem so I use Git branches in order to save every try. It's
> just that I'm looking for a 'global' place in my system where I can
> save code ideas and useful snippets not particular to any project.
> Quick access could be useful for some copy/paste operations...
> I don't know.
> 
> How would you set this up? A git folder 'snippets' maybe?
> 
> Thanks for your ideas.

I don't think there is a one-size-fits-all solution.

Setting up a 'snippets' repository sounds good if you just want to be 
able to look back at what you've done and/or have a place to stash away 
quick tests. I have set up a 'sandbox' folder (unrevisioned) and put 
together a few shell aliases for easier access and it works pretty well. 
I almost never look back at that code though.

If you develop a lot of small scripts you think you'll reuse in your 
daily routine, you should add a dedicated 'bin' directory and add it to 
your PATH.

I've also seen people put together libraries of "personal helpers", say, 
libedwin, but I don't think such mashups offer any particular semantic 
gain. They will just bloat over time and be vastly unused in most 
projects.

So, I don't really know what you should do. I'd go for a throw away 
location for quick tests; *real* libraries/programs where reasonable. If 
you need a particular algorithm and know you've used it in project XY, 
just go back to this project and copy it. No big deal. If it's a 
generally applicable algorithm, extracting a library might be a good idea 
then.

Just one last hint: Don't be overly shy in creating new Git repositories. 
They're pretty cheap and a shared history for *deeply unrelated projects* 
is seldom sensible (IMO). GitHub doesn't restrict you in your number of 
public repositories so that's no deal breaker either. :-)

Snippet'ly yours,

-- 
Robert "Stargaming" Lehmann



More information about the Python-list mailing list