Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are your favorite skeleton files for the various languages? [closed]

It is useful to have skeleton or template files that you can just copy and use as a basis for a new script or app.

For example, I use the following ones (emacs with the auto-insert module automatically opens a copy of the appropriate skeleton file when I create a new file).

Perl:

#!/usr/bin/perl -w 

use strict;
use Getopt::Long;

my $verbose = 1;

GetOptions("verbose!" => \$verbose
) or die("options error");

C++:

#include <iostream>
#include <stdexcept>

int main(int argc, char** argv){
  try{

  }
  catch(std::exception& e){
    std::cerr << e.what() << std::endl;
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

Arguably, one could include basic code for boost::program_options etc.

What are your favorite skeleton files?

like image 548
Frank Avatar asked Feb 02 '09 03:02

Frank


2 Answers

The only skeleton file I have is for LaTeX.

\documentclass{article}
%\documentclass[11pt]{amsart}
\usepackage[dvips]{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{cancel}
\oddsidemargin0cm
\topmargin-1cm
\textwidth16.5cm
\textheight23.5cm
\parskip1ex
\parindent0ex
\begin{document}
\title{ ... }
\author{ ... }
\date{ ... }
\maketitle

\end{document}

Obviously I use this for writing math papers.

Otherwise, I always start from scratch. There's no programming language I can think of where the requisite infrastructure is more than you can keep around in your brain or take longer than 20 seconds to type out.

like image 101
ephemient Avatar answered Oct 08 '22 16:10

ephemient


My Perl templates look like this:

If I am opening a .pm module:

use MooseX::Declare;
class What::Ever {

};

1;

Or, if not on a MooseX::Declare project:

package What::Ever;
use Moose;

1;

If it's a .pl file:

#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';

Since I use autoinsert.el, I also have it ask me if I want to use FindBin; if so:

#!/usr/bin/env perl
use strict;
use warnings;
use feature ':5.10';

use FindBin qw($Bin);
use lib "$Bin/../lib";

The necessary emacs code is in my elisp repository at http://github.com/jrockway/elisp/blob/fd5d73530a117a13ddcde92bc1c22aba1bfde1f0/_local/auto-inserts.el.

Finally, I think you will prefer MooseX::Getopt to plain Getopt. It is a much more maintainable approach to writing "one-off" scripts. (The next few lines go something like:

use My::Script;                    # that's why we did the "use lib" thing
My::Script->new_with_options->run; # this parses the command line, creates a new object, and runs the script

All the important code goes in a class that can be unit tested, glued to a web app, etc.)

like image 30
jrockway Avatar answered Oct 08 '22 15:10

jrockway