一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
当前回答
重复的代码只会增加不必要的输入层来完成工作。
这些是必要的吗?
在大多数情况下,这些都是结构和装饰性的标记。它提供了代码、函数和语言的一致性。
因此,对于开发人员来说,它有点多余,因为我们已经见过它很多次了,但它确实向非开发人员和编译器传达了一些实际意义。
其他回答
样板文件是优秀程序员所避免的:重复。
它是可以被许多应用程序/上下文使用的代码,只需很少或没有更改。
样板纸(Boilerplate)起源于20世纪初的钢铁工业。
来自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
In practical terms, boilerplate code is the stuff you cut-n-paste all over the place. Often it'll be things like a module header, plus some standard/required declarations (every module must declare a logger, every module must declare variables for its name and revision, etc.) On my current project, we're writing message handlers and they all have the same structure (read a message, validate it, process it) and to eliminate dependencies among the handlers we didn't want to have them all inherit from a base class, so we came up with a boilerplate skeleton. It declared all the routine variables, the standard methods, exception handling framework — all a developer had to do was add the code specific to the message being handled. It would have been quick & easy to use, but then we found out we were getting our message definitions in a spreadsheet (which used a boilerplate format), so we wound up just writing a code generator to emit 90% of the code (including the unit tests).