What is boilerplate code?

前端 未结 14 667
终归单人心
终归单人心 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:01

    Boilerplate is what good programmers avoid: repetition.

    0 讨论(0)
  • 2020-12-04 05:02

    You can refer to it as "snippets" or more accurately "collection of snippets" . The term I think was coined from the press and printing industry, where they used actual "plates" and then re-used them as chunks again.. In modern-day internet it is a part of an ongoing (annoying IMHO) trend of using fancy terms for simple things in order to look more trendy and sophisticated . see RESPONSIVE = adaptable / fluid.

    0 讨论(0)
  • 2020-12-04 05:03

    Boilerplate in software development can mean different things to different people but generally means the block of code that is used over and over again.

    In MEAN stack development, this term refers to code generation through use of template. It's easier than hand coding the entire application from scratch and it gives the code block consistency and fewer bugs as it is clean, tested and proven code and it's open source so it is constantly getting updated or fixed therefore it saves a lot of time as using framework or code generator. For more information about MEAN stack, click here.

    0 讨论(0)
  • 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).

    0 讨论(0)
  • 2020-12-04 05:11

    It's code that can be used by many applications/contexts with little or no change.

    Boilerplate is derived from the steel industry in the early 1900s.

    0 讨论(0)
  • 2020-12-04 05:12

    Joshua Bloch has a talk about API design that covers how bad ones make boilerplate code necessary. (Minute 46 for reference to boilerplate, listening to this today)

    0 讨论(0)
提交回复
热议问题