Another idiom I wish were gone from phobos/druntime
Chris via Digitalmars-d
digitalmars-d at puremagic.com
Fri Feb 6 07:59:04 PST 2015
On Friday, 6 February 2015 at 15:43:42 UTC, ketmar wrote:
> On Fri, 06 Feb 2015 15:08:55 +0000, Chris wrote:
>
>> On Friday, 6 February 2015 at 14:29:16 UTC, ketmar wrote:
>>> On Fri, 06 Feb 2015 14:04:39 +0000, Chris wrote:
>>>
>>>> auto opSlice(size_t low, size_t high)
>>> ...
>>>>
>>>> contract {
>>>> opSlice(size_t low, size_t high) {
>>>
>>> dead before the start.
>>
>> Why? Would you mind to elaborate on that a little? ;)
>
> p.s. and people will avoid using features that involves heavily
> copy-
> pasting, and has no error protection (imagine overloaded
> functions). so
> in this form it will be the feature that people will mark as
> "existent",
> but will not use, 'cause it's not comfortable enough.
Hm. But the compiler can check, if the signature is ok. E.g.
@contract auto opSlice(size_t low, size_t high) {
return bla;
}
contract {
opSlice(size_t low, size_t high) {
assert(low < high);
}
opSlice(int low, int high) { // <--- Error
}
}
or
contract {
auto opSlice(size_t low, size_t high) {
// Implementation
}
// contract
assert (low < high);
}
Dunno. I like it, if things can be put aside in blocks, like
unittest or debug.
More information about the Digitalmars-d
mailing list