契约式设计 契约式编程 Design by contract
Design by contract - Wikipedia https://en.wikipedia.org/wiki/Design_by_contract
What is the use of "assert" in Python? - Stack Overflow https://stackoverflow.com/questions/5142418/what-is-the-use-of-assert-in-python
7. Simple statements — Python 3.6.6rc1 documentation https://docs.python.org/3/reference/simple_stmts.html#assert
7.3. The assert
statement¶
Assert statements are a convenient way to insert debugging assertions into a program:
assert_stmt ::= "assert"expression
[","expression
]
The simple form, assert expression
, is equivalent to
if __debug__:
if not expression: raise AssertionError
The extended form, assert expression1, expression2
, is equivalent to
if __debug__:
if not expression1: raise AssertionError(expression2)
These equivalences assume that __debug__
and AssertionError
refer to the built-in variables with those names. In the current implementation, the built-in variable __debug__
is True
under normal circumstances, False
when optimization is requested (command line option -O). The current code generator emits no code for an assert statement when optimization is requested at compile time. Note that it is unnecessary to include the source code for the expression that failed in the error message; it will be displayed as part of the stack trace.
Assignments to __debug__
are illegal. The value for the built-in variable is determined when the interpreter starts.
7.4.
契约式设计 契约式编程 Design by contract的更多相关文章
- 重构25-Introduce Design By Contract checks(契约式设计)
契约式设计(DBC,Design By Contract)定义了方法应该包含输入和输出验证.因此,可以确保所有的工作都是基于可用的数据,并且所有的行为都是可预料的.否则,将返回异常或错误并在方法中进行 ...
- groovy动态类型--能力式设计
动态类型 动态类型中的类型是在运行时推断的,方法及其参数也是在运行时检查的. 能力式设计 被称作鸭子模式:他有这么一个观点:如果它走路像鸭子,叫起来也像鸭子,那么他就是一只鸭子. 契约式设计 相当于J ...
- JML契约式设计——第三单元学习小结
一.前言 本单元作业都是关于JML(Java Modeling Language),JML是一种契约式设计(Design by Contract)的语言,契约式设计的主要目的是希望程序员能够在设计程序 ...
- 契约式设计(DbC)感想(二)
契约式设计6大原则的理解 在<Design by Contract原则与实践>中,作者定义了契约式设计的6大原则: 区分命令和查询: 将基本查询和派生查询区分开: 针对每个派生查询,设定一 ...
- 契约式设计(DbC)感想(一)
契约式设计可以理解为正则编程的一种实践: 如果用我的三脚猫能力将这种实践方法形式化的话,大致如下(如有不正确处,请不吝指正): 1.对于方法Method的precondition & post ...
- 重构第25天 引入契约设计(Introduce Design By Contract checks)
理解:本文中的”引入契约式设计”是指我们应该对应该对输入和输出进行验证,以确保系统不会出现我们所想象不到的异常和得不到我们想要的结果. 详解:契约式设计规定方法应该对输入和输出进行验证,这样你便可以保 ...
- 企业级的响应式设计(Responsive design at enterprise level)译
导言 响应式设计是现在人们谈论的热点,但如何部署,特别是在有多种设备的大型项目中如何组织响应式设计,响应式设计和可伸缩性(Scalable)有什么区别?这都是需要解决的难题. 优化用户经验——Opti ...
- 响应式web设计(Responsive web design)
在全面进入互联网时代后,随着各种移动设备的普及,移动互联网更加受到大众的青睐.由于移动互联网的使用量远远超出了传统互联网的使用量,移动设备也正在逐渐超越桌面设备.因为用户在移动设备上的使用习惯不同,U ...
- 说服式设计(persuasive design)的行为模型
转自:http://www.sharetk.com/html/ued/User-Research/1404.html 一 模型简介 BJ Fogg提出了一个新的理解人类行为的模型,他称之为Fogg b ...
随机推荐
- C#语言之字符串和正则表达式
本文将完成以下两个目标: 一.创建字符串: 二.正则表达式: 首先,我先来介绍一下System.String类: System.String是一个类,专门用于存储字符串,允许对字符串进行许多操作. 使 ...
- LeetCode(80)Remove Duplicates from Sorted Array II
题目 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...
- Struts2执行原理
[原理图] [MVC] [执行过程(重要!!!!!)] 1) 客户端浏览器发出请求时,被Tomcat服务器所接收.Tomcat容器将用户的请求封装为HttpServletRequest对象 2) 请求 ...
- 2016阿里校招python研发面试
一面: 面:说说你们学校的主修课程. 学校开的全是尼玛java课,这个我是想了有一会的. 面:看你简历写了会jquery,来问你个简单的jquery问题 :jQuery支不支持css引入. 呵呵 面: ...
- BZOJ 1509[NOI 2003]逃学的小孩 树形dp
1509: [NOI2003]逃学的小孩 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 995 Solved: 505[Submit][Status][ ...
- HDU 4436 (后缀自动机)
HDU 4436 str2int Problem : 给若干个数字串,询问这些串的所有本质不同的子串转换成数字之后的和. Solution : 首先将所有串丢进一个后缀自动机.由于这道题询问的是不同的 ...
- Python基础教程笔记——第1章
1.8 函数 pow(x,y) x^y abs(x) 取数的绝对值 round(x) 会把浮点数四舍五入为最接近的整数 floor(x) 向下取整的函数,但是需要先imp ...
- 解决使用FusionCharts以后从后台获取数据中文乱码的问题
在使用FusionCharts 的时候 ,发现了一个非常奇怪的问题, 一旦在页面上加入一个chart组件, 不管给不给数据, 从后台取到的数据, 中文就全变成了乱码. 由于我使用的是object ar ...
- Linux下建立虚拟内存
查看目前虚拟内存状况 free -m -m表示以MB的单位显示 建立虚拟内存文件 先用df -h确认要放虚拟内存文件的位置,假设为 /data/swap/swap1 创建2G的虚拟内存并启用: dd ...
- codevs——3064 求和
3064 求和 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 青铜 Bronze 题解 查看运行结果 题目描述 Description 输入一个数x(x <= ...