Is anybody up for building a collection of code snippets?

Is anybody up for building a collection of code snippets?

If you're like me, you've got a folder with some .pas files in it that have snippets of code that just don't fit anywhere. For example, I'll spend some time trying to figure out how to do something, searching around the web and grabbing bits and pieces of things until I've gotten something that works. Then I'll save that code to a file with some comments (if needed) for use later.

Sometimes it's just a few lines of code, and sometimes it's an entire class or two.

Some of these snippets work their way into a "common.pas" file, but mostly they're not exhaustive enough to become a separate component or library.

For instance, I've got some code for when I want to use a TPageControl that has dynamically created TTabsheets that contain some kind of edit control (eg., a TMemo Aligned to Client with certain attributes set), similar to what you'd build a tabbed editor around. This is code that cannot reasonably be reduced to a set of generics; templates perhaps, but Delphi doesn't support them. Another example is a code snippet that you'd attach to an OnColClick event to sort the contents of a grid or TListView (one common method that handles all types of data used in that particular view).

The thing is, none of these code snippets are generally useful as-is. I'll copy and past them, then modify them for my needs. The key point is that they solve a specific problem that's not necessarily easy to figure out. They end up saving me quite a bit of time.

Electronic hardware designers have access to books full of small circuit designs like oscillators, filters, buffer amps, etc. (Maybe they've become obsolete with modern CAD software?)

I'm wondering if anybody would be interested in a community project that would produce something like this? I'm sure some will say it's redundant, and to use a git repo for instance. Or "that's what SO is for!" If it's that simple, then why do you keep your own little library of code snippets on hand?

To get started, I'm curious how others manage or maintain their own libraries of code snippets?

I've worked on projects where we used a GExperts-based snippet collection loaded up with code snippets commonly used on the project. But IRRC, it was a royal PITA to maintain, because GExperts wasn't well-suited for this purpose. However, I'm usually informed it's the best thing anybody has yet found. (I haven't looked hard, so I don't know.)

I keep mine mostly as .pas files in a folder named "tips-and-tricks". I think I've got a dozen or so going back a decade or more, but I'll often spend time digging through old code looking for stuff I remember coding that I never thought to separate out.

I guess this is best described as a Knowledge Base of code snippets. What would be the best way to host it (as a container)?

Would you be interested in contributing what YOU have collected over the years?

Comments

Post a Comment