DIP 1003: remove `body` as a keyword

Chris Wright via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Sun Nov 20 08:48:47 PST 2016


On Sun, 20 Nov 2016 14:35:16 +1300, rikki cattermole wrote:
> I was thinking maybe option 3 but not have the body first.
> 
> int func(int arg) {
> 	return 8 * arg;
> } in {
> 	assert(arg > 0);
> } out(int value) {
> 	assert(1);
> }
> 
> Would break code but its a simple rearrangement.

Right now, the normal flow when reading a function is:

* Doc comment: What did the author think important for me to know?
* Signature: How do I call it so the compiler will accept it?
* In contract: What sort of parameters are acceptable?
* Out contract: What invariants apply to the result?
* Body: I only need to read this if the rest didn't help.

This is ordered by importance.

By hanging the contracts off the end, you're making them harder to 
notice. That's not ideal.


More information about the Digitalmars-d-announce mailing list