boilerplate code —— 不重要,但是又没它不行的代码

访问量: 3043

经常在英文材料中看到这个词。, iciba给出的意思都不准确,(样板文件,钢炉锅板)。  估计“样板文件”略有其真实的意思。但实际上,我们可以翻译的再“通俗”一些。。。

from wiki: 

Boilerplate code
From Wikipedia, the free encyclopedia
In computer programming, boilerplate code or boilerplate is the sections of code that have to be included in many places with little or no alteration. It is often used when referring to languages that are considered verbose, i.e. the programmer must write a lot of code to do minimal jobs. The need for boilerplate can be reduced through high-level mechanisms such as metaprogramming (which has the computer automatically write the needed boilerplate text), convention over configuration (which provides good default values, reducing the need to specify program details in every project) and model-driven engineering (which uses models and model-to-code generators, eliminating the need for boilerplate manual code).

不重要,但是没它不行。用来跟verbose同义。 可以通过 metaprogramming, convention over configuration, 以及 mode-driven engineering 来改善。

可以通过 convention over configuration 来改善的例子,就是 struts, spring 中我们深恶痛绝的 xml 文件,都可以在 rails 中被COC干掉。

订阅/RSS Feed