Rant after trying Rust a bit

Manu via Digitalmars-d digitalmars-d at puremagic.com
Sat Jul 25 06:59:57 PDT 2015


On 25 July 2015 at 18:48, Walter Bright via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
> On 7/24/2015 11:10 PM, Jonathan M Davis wrote:
>>
>> So, maybe we should look at something along those lines rather than
>> proliferating the top-level function overloading like we're doing now.
>
>
> Consider the following pattern, which I see often in Phobos:
>
>     void foo(T)(T t) if (A) { ... }
>     void foo(T)(T t) if (!A && B) { ... }
>
> from a documentation (i.e. user) perspective. Now consider:
>
>     void foo(T)(T t) if (A || B)
>     {
>          static if (A) { ... }
>          else static if (B) { ... }
>          else static assert(0);
>     }
>
> Makes a lot more sense to the user, who just sees one function that needs A
> or B, and doesn't see the internal logic.

This! I've felt this way with phobos in particular for ages.
I've argued this exact case before, and it's been rejected.
I much prefer static if inside functions rather than pollute the
namespace (and docs) with a bunch of overloads. Also, these symbols
with lots of constraints can get really long!


More information about the Digitalmars-d mailing list