一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。

附带问题,这个词是谁发明的?


当前回答

来自whatis.techtarget.com:

In information technology, a boilerplate is a unit of writing that can be reused over and over without change. By extension, the idea is sometimes applied to reusable programming as in "boilerplate code." The term derives from steel manufacturing, where boilerplate is steel rolled into large plates for use in steam boilers. The implication is either that boilerplate writing has been time-tested and strong as "steel," or possibly that it has been rolled out into something strong enough for repeated reuse.

编程之外:

样板可以与特定类型的模板进行比较 被认为是一个填空样板。一些典型的 样板文件通常包括:任务陈述、安全警告 使用的安装程序、版权声明和责任 免责声明。

以我作为程序员的经验来看,合适的样板代码通常是一堆你开始的代码,这些代码不太大,也不太复杂,不能称为框架。

HTML5 Boilerplate就是一个典型的例子。

其他回答

样板文件是一种写作单元,可以不作任何更改地反复使用。通过扩展,这种思想有时应用于可重用编程,如“样板代码”

“样板代码”是任何看似重复的代码,它们一次又一次地出现,以获得一些看起来应该简单得多的结果。

这是一个主观的定义。

这个术语来源于报纸行业的“标准版”:wiki

在词源上,术语boilerplate: from http://www.takeourword.com/Issue009.html…

Interestingly, the term arose from the newspaper business. Columns and other pieces that were syndicated were sent out to subscribing newspapers in the form of a mat (i.e. a matrix). Once received, boiling lead was poured into this mat to create the plate used to print the piece, hence the name boilerplate. As the article printed on a boilerplate could not be altered, the term came to be used by attorneys to refer to the portions of a contract which did not change through repeated uses in different applications, and finally to language in general which did not change in any document that was used repeatedly for different occasions.

编程中的样板文件由什么组成?正如其他人可能已经指出的那样,它 只是一大块代码,一遍又一遍地复制,很少或 在这个过程中没有对它做任何改变。

Boilerplate definition is becoming more global in many other programming languages nowadays. It comes from OOP and hybrid languages that have become OOP and were before procedual have now the same goal to keep repeating the code you build with a model/template/class/object hence why they adapt this term. You make a template and the only things you do for each instance of a template are the parameters to individualize an object this part is what we call boilerplate. You simply re-use the code you made a template of, just with different parameters.

同义词 蓝图是样板 模板是样板 页脚是一个样板 用于多种用途的设计模式是一个样板 邮件的签名是一份样板文件

样板代码是指可以反复使用的一段代码。另一方面,任何人都可以说它是一段可重用的代码。

这个词实际上来自钢铁行业。

对于一点历史,根据维基百科:

在19世纪90年代,样板版实际上是铸造或冲压成金属,准备印刷,并分发给美国各地的报纸。直到20世纪50年代,成千上万的报纸从美国最大的供应商西部报业联盟那里收到并使用了这种样板文件。有些公司还以样板文件的形式发布新闻稿,这样它们就必须按书面形式打印出来。

根据维基百科:

In object-oriented programs, classes are often provided with methods for getting and setting instance variables. The definitions of these methods can frequently be regarded as boilerplate. Although the code will vary from one class to another, it is sufficiently stereotypical in structure that it would be better generated automatically than written by hand. For example, in the following Java class representing a pet, almost all the code is boilerplate except for the declarations of Pet, name and owner: public class Pet { private PetName name; private Person owner; public Pet(PetName name, Person owner) { this.name = name; this.owner = owner; } public PetName getName() { return name; } public void setName(PetName name) { this.name = name; } public Person getOwner() { return owner; } public void setOwner(Person owner) { this.owner = owner; } }