前提条件,后置条件和计算机术语中的不变量有什么区别 [英] What are the differences pre condition ,post condition and invariant in computer terminology

查看:452
本文介绍了前提条件,后置条件和计算机术语中的不变量有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读 JCIP ,并对条款有些混淆:

I am reading JCIP and getting a little bit confused with the terms :


  1. 前置条件

  2. 发布条件

  3. 不变式

$ b $

推荐答案

可能有很多编写Java的问题,特别是多线程代码,如果你不能理解这些简单的想法:

You'll have a lot of problems writing Java, especially multi-threaded code, if you can't understand these simple ideas:


  1. 前提条件是必须在调用方法之前为true。该方法告诉客户这是我对你的期望。

  2. 后置条件是方法完成后必须为真的事情。该方法告诉客户这是我答应为你做的。

  3. 不变式是总是真实的,不会改变的事情。该方法告诉客户如果这是真的,在你打电话之前,我保证在我完成后它仍然是真实的。

它们都是一个名为按合同编程的想法的一部分。它是由一个名叫 C.A.R. Hoare 。 Bertrand Meyer构建了一种面向对象的语言,名为 Eiffel 。没有人使用它太多,但他有一天在阳光下因为它。

They're all part of an idea called "programming by contract". It was invented by a guy named C.A.R. Hoare. Bertrand Meyer built an object oriented language called Eiffel around it. No one uses it much, but he had a day in the sun because of it.

埃菲尔不是很受欢迎。

Eiffel isn't very popular. There are over four million questions on SO as I write this, but only 32 of them are tagged "eiffel".

更新:有29,966,392个问题,SO在29- 2016年6月。只有92人被标记为艾菲尔。埃菲尔问题的百分比大致保持在约0.00077%。

Update: There were 11,966,392 question on SO on 29-Jun-2016. Only 92 of them were tagged "eiffel". The percentage of Eiffel questions is staying roughly constant at ~0.00077%.

我已经纠正了 - 谢谢你,flamingpenguin。我已更新了我的答案。

I stand corrected - thank you, flamingpenguin. I've updated my answer.

这篇关于前提条件,后置条件和计算机术语中的不变量有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆