Using Skels

This time I am writing mainly for beginners, and not specifically for Perl programmers, but any programmer of any language. Skels (my abbreviation for skeletons) are totally relevant in a programming environment.

What are skeletons? There are different names for the same thing. You can call it a template, or call it a snippet. Skels, for me, are both: pieces of code, that might work or not, that might have placeholders or not, but that save you time by remembering how something is done.

I have a bunch of skeletons ready to use in my Emacs. I would like to have more, but sometimes I am too lazy and forget that with skeletons I can be yet more lazy. Some examples of skeletons: the line used in XML to refer to an external CSS file; an empty HTML document; an empty LaTeX document with the more usual packages; a LaTeX presentation document; a common POD document structure; etc.

This can be done in different ways. TextMate let you start typing something, press tab, and get your snippet expanded. I am sure vim, komodo and other editors have similar mechanisms. The important is not what editor to use. The important is to have the skeletons ready to use.

4 Comments

I use GViM, which has filters (In ViM, see `:help filter`). With them, I can use Sub::Starter because writing a usage statement is easier.

"sometimes I am too lazy and forget that with skeletons I can be yet more lazy".

Totally agree. And also this apply to system administrators, UX designers, etc...

In vim another approach to completion, maybe to use starters for new files:

autocmd BufNewFile *.pm 0r ~/.vim/skeleton.pm
autocmd BufNewFile *.pl 0r ~/.vim/skeleton.pl

I call them templates, and they make everything easier IMO. From initial idea to banging code out in less than 5 minutes. It also gives you consistency between projects - useful when you are trying to remember what a function does. Since you use it often enough, it makes things easier. I've got several variants of the same basic template, pick the one with the features already in place that I need, and I'm off doing the code that is needed, not rewriting code I've already written.

chromatic recently wrote on this subject as well: http://www.modernperlbooks.com/mt/2010/05/a-collection-of-silly-little-snippets.html . Certainly it would be very useful if we could download such skeletons/templates/snippets for common tasks from a central repository.

Leave a comment

About Alberto Simões

user-pic I blog about Perl. D'uh!