页面

分类

总结:为什么人为的宽契约是坏的

2014/3/22, by wingfire ; 分类: 计算机技术, 程序设计; 0 comments

from: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3877.pdf

This section provides a concise summary how appropriately narrow contracts are superior compared to artificially wide ones:

  • RUNTIME COST: Validating and/or otherwise analyzing input—even if we do nothing else—always has a runtime cost: Sometimes that cost is relatively small, sometimes it is not, and sometimes the cost completely overwhelms that of accomplishing the useful work the function is intended to perform.

  • DEVELOPMENT COST: Artificially defining additional behaviors (i.e., beyond input validation) requires more up-front effort by library developers to design, document, implement, and test; the more significant cost, however, is born by application developers when these added behaviors serve only to mask defects resulting from library misuse.

  • CODE SIZE: Implementing the additional behavior will necessarily result in larger executables. On all real-world computers, more code generally runs slower—even when that code it is never executed!

  • EXTENSIBILITY: Artificially defining behavior that is not known to be useful severely impedes adding backward-compatible extensions should new and truly useful functionality be discovered in the future.

  • DEFENSIVE PROGRAMMING: Eliminating all undefined behavior precludes robust library implementations from detecting and reporting out-of-contract use depending on the build mode. If the local function contract always specifies the behavior for all possible input/state combinations, we lose the substantial benefit of this very important, extremely useful quality-of-implementation feature of robust library software for application development.

添加评论:

 
 the email would not displayed
 

您可以使用 Markdown 语法。

您必须启用浏览器的 JavaScript 功能才能发表评论。