您最喜欢的各种语言的骨架文件是什么?

时间:2009-02-02 03:47:19

标签: ide code-generation

拥有可以复制并用作新脚本或应用程序基础的框架或模板文件非常有用。

例如,我使用以下内容(当我创建新文件时,带有自动插入模块的emacs会自动打开相应骨架文件的副本。)

的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;
}

可以说,可以包含boost::program_options等的基本代码。

您最喜欢的骨架文件是什么?

7 个答案:

答案 0 :(得分:3)

我的Perl模板如下所示:

如果我打开.pm模块:

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

};

1;

或者,如果没有MooseX::Declare项目:

package What::Ever;
use Moose;

1;

如果是.pl文件:

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

由于我使用autoinsert.el,我也问过我是否要使用FindBin;如果是的话:

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

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

必要的emacs代码位于http://github.com/jrockway/elisp/blob/fd5d73530a117a13ddcde92bc1c22aba1bfde1f0/_local/auto-inserts.el的elisp存储库中。

最后,我认为你会更喜欢MooseX::Getopt到普通的Getopt。编写“一次性”脚本是一种更易于维护的方法。 (接下来的几行是这样的:

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

所有重要的代码都在一个可以进行单元测试,粘贴到Web应用程序等的类中。)

答案 1 :(得分:3)

我唯一的骨架文件是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}

显然我用它来写数学论文。

否则,我总是从头开始。没有任何编程语言,我可以想到必需的基础设施比你在大脑中保留的更多,或者输入的时间超过20秒。

答案 2 :(得分:1)

在visual studio中,它们被称为项目文件;我目前最喜欢的是Windows应用程序; - )

答案 3 :(得分:1)

<强>爪哇

package edu.vt;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Template
{
   private Log log = LogFactory.getLog(getClass());

   /* Constructors
   ***************************************************************************/

   public Template()
   {
   }

   /* Accessors/Mutators
   ***************************************************************************/

   /* Local Methods
   ***************************************************************************/
}

package testing.edu.vt;

import edu.vt.Template;
import junit.framework.TestCase;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class TemplateTestCase extends TestCase
{
   private final Log log = LogFactory.getLog(getClass());

    public TemplateTestCase(final String name)
    {
      super(name);
    }

    protected void setUp()
    {
    }

    protected void tearDown()
    {
    }

    public void testLifeCycle() throws Exception
    {
      assertTrue(true);
    }
}

答案 4 :(得分:1)

Python非常简单,但如果您使用快捷方式名称导入内容仍然有用,例如:

import sys
import numpy as np
import pylab as pyb
import matplotlib.pyplot as plt
import matplotlib as mpl

但是不要这样做:导入天网。

答案 5 :(得分:1)

Bourne Shell

#!/bin/sh

usage() {
cat <<EOF
  $0 <cmd>
cmd:
  samplecmd
EOF
}

cmd=${1}
shift

case ${cmd} in
    samplecmd)
        arg1=${arg1:-${1}} # arg list takes precedence over env var
        if [ "x${arg1}" = "x" ] ; then
            usage
        fi
        samplecmd ${arg1}
        ;;
    *)
        usage
        ;;
esac

我喜欢制作这样的小帮助脚本来记录我在shell中输入的命令。

答案 6 :(得分:0)

当我编写将成为OSS的代码时,我有一个简单的锅炉板模板,我可以键入许可证和许可证文本的URL。锅炉板上有作者详细信息,还有其他硬编码。

对于商业开发,我有一个带有公司信息的锅炉盘,以及标准的版权声明。

我没有保留任何标准骷髅,因为我发现我只是删除了内容并添加了我自己的内容。大多数情况都是不同的,只要手动抨击它就可以将骨架更改为匹配。

相关问题