Greenwashing

Steven Schveighoffer schveiguy at gmail.com
Thu May 28 15:37:19 UTC 2020


On 5/28/20 11:30 AM, Joseph Rushton Wakeling wrote:
> On Thursday, 28 May 2020 at 15:12:56 UTC, Steven Schveighoffer wrote:
>>> Not sure I agree about that TBH.  Inferred-by-default just means the 
>>> function signature doesn't by default tell you anything about what 
>>> properties you can rely on, and any change to the implementation may 
>>> alter the available properties, without any external sign that this 
>>> has happened.
>>
>> 1. Templates already do this, and it has not been a problem (much of 
>> Phobos and much of what I've written is generally templates).
> 
> Yes, but the user tends to have a lot of control there in practice, by 
> what template arguments they pass.  So the template is less of a black 
> box of surprise.  I also think there's a bit of an implicit motivation 
> for an author of templated code to try and _make_ the template args the 
> dominant factor there (because that makes the template more usable).

I think a ton of templates get written without considering attribute 
inference at all. It just happens to work because the compiler is 
guaranteed to have all the source.

I've seen people change a function in to a no-arg template function not 
even for inference, but to ensure the compiler only generates code if 
called. All of a sudden, it gets a new set of attributes, and nobody 
complains.

The most pleasant thing about template inference is that it generally 
works out well because it provides the most restrictive attributes it 
can. It doesn't get in the way of the author who doesn't care about 
attributes or the user who does care.

But it can also blow up if you can't figure out why some inference is 
happening and you expect something different. I think in addition to 
such a change to inference by default the compiler should provide a 
mechanism to explain how it infers things so you can root out the cause 
of it. I'd like to have this feature regardless of any defaults.

-Steve


More information about the Digitalmars-d mailing list