一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
当前回答
在词源上,术语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.
编程中的样板文件由什么组成?正如其他人可能已经指出的那样,它 只是一大块代码,一遍又一遍地复制,很少或 在这个过程中没有对它做任何改变。
其他回答
Joshua Bloch有一个关于API设计的演讲,涵盖了糟糕的API如何使样板代码成为必要。(参考样板文件的第46分钟,今天听这个)
软件开发中的样板对不同的人有不同的含义,但通常是指反复使用的代码块。
在MEAN栈开发中,这个术语指的是通过使用模板来生成代码。它比从头开始手动编码整个应用程序更容易,它提供了代码块的一致性和更少的错误,因为它是干净的,经过测试和验证的代码,而且它是开源的,所以它不断更新或修复,因此它在使用框架或代码生成器时节省了大量时间。有关MEAN stack的更多信息,请点击这里。
样板代码是指可以反复使用的一段代码。另一方面,任何人都可以说它是一段可重用的代码。
这个词实际上来自钢铁行业。
对于一点历史,根据维基百科:
在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; } }
样板文件是一种写作单元,可以不作任何更改地反复使用。通过扩展,这种思想有时应用于可重用编程,如“样板代码”
来自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就是一个典型的例子。