Feedback on Átila's Vision for D
JN
666total at wp.pl
Wed Oct 16 07:09:38 UTC 2019
On Tuesday, 15 October 2019 at 16:17:57 UTC, Atila Neves wrote:
>
> Meh:
>
> //C++20 concepts
> concept isAddable = requires (T x) { x + x; };
>
> // D
> enum isAddable(T) = is(typeof((T x) => x + x));
>
>
> We lose by one character ;)
I disagree. It's not just one character. C++ example is much
cleaner. Imagine not being experienced with C++ and D and seeing
these two examples.
C++ line of thought: we're defining a concept isAddable, which is
something that requires that there is some x that can be added to
itself.
D line of thought: we're defining an enum (why enum? why would I
want an enumeration here?) isAddable of type T which is something
that is a typeof (wait, why do I have to repeat the T here
again)?? What does that even mean "is(typeof())"?
It feels more complicated for a bystander. Actually,
__traits(compiles) would be even cleaner in this case, because
the is(typeof()) part, while could be considered a D idiom, feels
very unexpected.
More information about the Digitalmars-d
mailing list