digitalmars.D - Strengthening contract
- Kagamin (20/20) Nov 11 2014 http://forum.dlang.org/post/jftnpqyahnwacgkmslej@forum.dlang.org
- Idan Arye (10/31) Nov 11 2014 Contracts are a tool for enforcing the Liskov substitution
- Kagamin (2/2) Nov 12 2014 I mean, it's something to keep in mind, as I guess, such
- David Nadlinger (4/6) Nov 12 2014 It is documented: http://dlang.org/contracts (although it just
http://forum.dlang.org/post/jftnpqyahnwacgkmslej forum.dlang.org
c:\D\import\dfl\button.d(381): Error: function
dfl.button.Button.text cannot have
e an in contract when overriden function dfl.control.Control.text
does not have an in contract
This is the line 381:
override void text(Dstring txt) // setter
in
{
	if(txt.length)
		assert(!this.image, "Button image with text not supported");
}
body
{
	super.text = txt;
}
But if a button can't display image with text by design, it's its 
contract, that text can't be set with image, while the base class 
has no such restriction. What does it mean, DbC is incompatible 
with inheritance?
 Nov 11 2014
On Tuesday, 11 November 2014 at 15:31:07 UTC, Kagamin wrote:
 http://forum.dlang.org/post/jftnpqyahnwacgkmslej forum.dlang.org
 c:\D\import\dfl\button.d(381): Error: function
 dfl.button.Button.text cannot have
 e an in contract when overriden function 
 dfl.control.Control.text
 does not have an in contract
 This is the line 381:
 override void text(Dstring txt) // setter
 in
 {
 	if(txt.length)
 		assert(!this.image, "Button image with text not supported");
 }
 body
 {
 	super.text = txt;
 }
 But if a button can't display image with text by design, it's 
 its contract, that text can't be set with image, while the base 
 class has no such restriction. What does it mean, DbC is 
 incompatible with inheritance?
Contracts are a tool for enforcing the Liskov substitution 
principle(http://en.wikipedia.org/wiki/Liskov_substitution_principle). 
What you are trying to do violates the LSP because I can't set 
the text of a Control if what I have in hand happens to be it's 
subclass, Button.
Now, I'm not saying that you shouldn't do that assert - I think 
the best-practices work better as rules of thumb than as sacred 
religious rules - but since contracts are modeled after the LSP 
they are probably not the right tool for this job...
 Nov 11 2014
I mean, it's something to keep in mind, as I guess, such limitation is not documented and not obvious.
 Nov 12 2014
On Wednesday, 12 November 2014 at 10:15:45 UTC, Kagamin wrote:I mean, it's something to keep in mind, as I guess, such limitation is not documented and not obvious.It is documented: http://dlang.org/contracts (although it just says "no useful effect" instead of "illegal") David
 Nov 12 2014








 
  
  
  "David Nadlinger" <code klickverbot.at>
 "David Nadlinger" <code klickverbot.at>