Another idiom I wish were gone from phobos/druntime
deadalnix via Digitalmars-d
digitalmars-d at puremagic.com
Wed Feb 4 16:47:19 PST 2015
On Thursday, 5 February 2015 at 00:24:15 UTC, Andrei Alexandrescu
wrote:
> I'm seeing another idiom that seems to become fashionable.
> Consider this excerpt from
> https://github.com/D-Programming-Language/phobos/blob/master/std/algorithm/iteration.d#L407:
>
> auto opSlice(size_t low, size_t high)
> in
> {
> assert(low <= high);
> }
> body
> {
> import std.range : take;
> return this[low .. $].take(high - low);
> }
>
> which of course trivially boils down to:
>
> auto opSlice(size_t low, size_t high)
> {
> assert(low <= high);
> import std.range : take;
> return this[low .. $].take(high - low);
> }
>
> What advantage could possibly be in transforming a 5-liner into
> a 9-liner? Are we really aiming at writing the maximum possible
> lines of code here and using as many language features as
> possible everywhere?
>
> I think we should dust off that Phobos contributors' guide.
> Sadly, there is little we can do against the more subtle issues.
>
>
> Andrei
Various things.
1/ the initial is overly long because the styling is wasteful.
void foo() in {
...
} body {
...
}
Is simply one line more than not using contracts.
2/ The semantic is not 100% equivalent (well at least the
intended semantic) as the in contract should be chosen based on
the static type while the implementation on the dynamic one. That
mean the contract should tun in the caller.
I don't think this is what DMD does currently, but that is what
is intended. See for instance :
https://issues.dlang.org/show_bug.cgi?id=12247
https://issues.dlang.org/show_bug.cgi?id=6857
More information about the Digitalmars-d
mailing list