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

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


当前回答

简而言之,样板代码是需要包含在应用程序中的重复代码,程序/框架几乎没有改变,并且对应用程序的逻辑没有任何贡献。当您编写伪代码时,您可以删除样板代码。建议使用合适的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;}   
  }   
}  

其他回答

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.

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

简而言之,样板代码是需要包含在应用程序中的重复代码,程序/框架几乎没有改变,并且对应用程序的逻辑没有任何贡献。当您编写伪代码时,您可以删除样板代码。建议使用合适的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;}   
  }   
}  

在词源上,术语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.

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

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

软件开发中的样板对不同的人有不同的含义,但通常是指反复使用的代码块。

在MEAN栈开发中,这个术语指的是通过使用模板来生成代码。它比从头开始手动编码整个应用程序更容易,它提供了代码块的一致性和更少的错误,因为它是干净的,经过测试和验证的代码,而且它是开源的,所以它不断更新或修复,因此它在使用框架或代码生成器时节省了大量时间。有关MEAN stack的更多信息,请点击这里。