What is boilerplate code?

前端 未结 14 740
终归单人心
终归单人心 2020-12-04 04:41

A coworker had never heard of this, and I couldn\'t provide a real definition. For me, it\'s always been an instance of \'I-know-it-when-I-see-it\'.

Bonus question,

14条回答
  •  不知归路
    2020-12-04 05:06

    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).

提交回复
热议问题