一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
一位同事从未听说过这个词,我也无法给出一个确切的定义。对我来说,这一直是一个“我看到什么就知道什么”的例子。
附带问题,这个词是谁发明的?
当前回答
样板文件是优秀程序员所避免的:重复。
其他回答
简而言之,样板代码是需要包含在应用程序中的重复代码,程序/框架几乎没有改变,并且对应用程序的逻辑没有任何贡献。当您编写伪代码时,您可以删除样板代码。建议使用合适的Editor来生成样板代码。
在HTML中,接口中的样板代码。
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body> </body>
</html>
在c#语言中,属性的样板代码。
class Price
{
private string _price;
public string Price
{
get {return _price;}
set {_price= value;}
}
}
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).
软件开发中的样板对不同的人有不同的含义,但通常是指反复使用的代码块。
在MEAN栈开发中,这个术语指的是通过使用模板来生成代码。它比从头开始手动编码整个应用程序更容易,它提供了代码块的一致性和更少的错误,因为它是干净的,经过测试和验证的代码,而且它是开源的,所以它不断更新或修复,因此它在使用框架或代码生成器时节省了大量时间。有关MEAN stack的更多信息,请点击这里。
Joshua Bloch有一个关于API设计的演讲,涵盖了糟糕的API如何使样板代码成为必要。(参考样板文件的第46分钟,今天听这个)
样板文件是优秀程序员所避免的:重复。