Date: Sat, 30 Apr 2022 14:52:53 -0400
On Sat, Apr 30, 2022 at 11:07 AM William Linkmeyer <wlink10_at_[hidden]> wrote:
>
> Jason — you raise fair and compelling points.
>
> But I strongly believe we are overlooking the importance of making good code *easy* to write. Explicit template arguments might help.
But that requires that we consider such a thing to be "good code".
It may be *necessary* in certain circumstances. It may be quite useful
in specific cases. But is it really "good"?
Consider the OP's primary motivational case. This feature is prompted
by C/C++'s integer promotion rules: the type of `a + b` may be
surprising for smaller integers. By all rights, the correct solution
would be to take out the surprising part. But since that's way
unfeasible, the alternative is to force the user to demonstrate that
they are aware of promotion and to explicitly specify the type.
This isn't a solution; it's a hack. A useful one, but it's still a hack.
There are other circumstances where shutting down type deduction is
good. But are they often enough to be worthy of a language feature?
And when I say "worthy", I don't mean in terms of standard definition
or compiler implementation. Every language feature, no matter how
seemingly trivial, has some cost to it. People have to learn what it
means so that they can read other people's code. And so forth.
Is this particular use case worth that? Is this particular use case
sufficiently common that the current `type_identity_t` trick needs to
be more explicit?
>
> Jason — you raise fair and compelling points.
>
> But I strongly believe we are overlooking the importance of making good code *easy* to write. Explicit template arguments might help.
But that requires that we consider such a thing to be "good code".
It may be *necessary* in certain circumstances. It may be quite useful
in specific cases. But is it really "good"?
Consider the OP's primary motivational case. This feature is prompted
by C/C++'s integer promotion rules: the type of `a + b` may be
surprising for smaller integers. By all rights, the correct solution
would be to take out the surprising part. But since that's way
unfeasible, the alternative is to force the user to demonstrate that
they are aware of promotion and to explicitly specify the type.
This isn't a solution; it's a hack. A useful one, but it's still a hack.
There are other circumstances where shutting down type deduction is
good. But are they often enough to be worthy of a language feature?
And when I say "worthy", I don't mean in terms of standard definition
or compiler implementation. Every language feature, no matter how
seemingly trivial, has some cost to it. People have to learn what it
means so that they can read other people's code. And so forth.
Is this particular use case worth that? Is this particular use case
sufficiently common that the current `type_identity_t` trick needs to
be more explicit?
Received on 2022-04-30 18:53:43