digitalmars.D - Ghost fields for Contract Programming
- bearophile (5/5) Oct 09 2010 A possible enhancement for Contract Programming:
- Tomek =?UTF-8?B?U293acWEc2tp?= (12/13) Oct 09 2010 by the class invariant.
- bearophile (12/22) Oct 09 2010 D2 has several ways to perform conditional compilation, so you may imple...
- bearophile (3/4) Oct 09 2010 Sorry, I meant, 'And ghost fields aren't very important to start with'.
- Tomek =?UTF-8?B?U293acWEc2tp?= (6/43) Oct 09 2010 OK, thx for explanation. But as you said, ghost fields aren't that impor...
- Denis Koroskin (4/16) Oct 09 2010 =
A possible enhancement for Contract Programming: http://d.puremagic.com/issues/show_bug.cgi?id=5027 This is not meant as a replacement for "old" (that allows to refer to the state at the entry to the instance method). Bye, bearophile
Oct 09 2010
bearophile napisał:The ghost fields may be used to store partial computations useful to reduce the work doneby the class invariant. You can do: class C { version(unittest) int temp; invariant() { // use temp } } Or am I missing something? -- Tomek
Oct 09 2010
Tomek S.:You can do: class C { version(unittest) int temp; invariant() { // use temp } } Or am I missing something?D2 has several ways to perform conditional compilation, so you may implement hand-made ghost fields using a version(debug). And ghost fields are very important to start with (I was not sure to submit an enhancement request). There are two things that maybe you are missing. A field like: version(unittest) int temp; gets compiled when you use the -unittest, and gets removed otherwise. While the presence of ghost fields is determined by the presence of active contracts, that currently are run with the code is compiled in non-release build (so they are not related to the -unittest switch). The second problem is that inside a method foo() of that class C you may write: void foo() { version(unittest) temp++; } But well implemented ghost fields are never visible inside the body of methods. So if you try to use them inside foo() the compiler has to raise a compile error. Bye, bearophile
Oct 09 2010
And ghost fields are very important to start with (I was not sure to submit an enhancement request).Sorry, I meant, 'And ghost fields aren't very important to start with'. Bye, bearophile
Oct 09 2010
bearophile napisał:Tomek S.:OK, thx for explanation. But as you said, ghost fields aren't that important and conditional compilation can provide a crude-but-working implementation, so I doubt the ROI would be positive. -- TomekYou can do: class C { version(unittest) int temp; invariant() { // use temp } } Or am I missing something?D2 has several ways to perform conditional compilation, so you may implement hand-made ghost fields using a version(debug). And ghost fields are very important to start with (I was not sure to submit an enhancement request). There are two things that maybe you are missing. A field like: version(unittest) int temp; gets compiled when you use the -unittest, and gets removed otherwise. While the presence of ghost fields is determined by the presence of active contracts, that currently are run with the code is compiled in non-release build (so they are not related to the -unittest switch). The second problem is that inside a method foo() of that class C you may write: void foo() { version(unittest) temp++; } But well implemented ghost fields are never visible inside the body of methods. So if you try to use them inside foo() the compiler has to raise a compile error.
Oct 09 2010
On Sat, 09 Oct 2010 23:51:44 +0400, Tomek Sowi=C5=84ski <just ask.me> wr= ote:bearophile napisa=C5=82:=The ghost fields may be used to store partial computations useful to =How often do you *run* your application with unittests enabled?reduce the work doneby the class invariant. You can do: class C { version(unittest) int temp; invariant() { // use temp } } Or am I missing something?
Oct 09 2010