Thread overview | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 05, 2013 finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Attachments:
| Currently D will compile templated code that is syntactically correct but semantically always incorrect (ie regardless of template parameters), eg the following: regardless of T, b is not in scope and hence this template cannot be instantiated without CT error. So would it be possible to detect such kind of errors (ie CT error regardless of template params) without having to instantiate the template? Sure this could be detected with unittests in a perfect world but that gives an additional level of safety. Likewise with template constraints, where the code wouldn't be able to compile given template constraints, but this case is harder. ---- void fun(T)(){ int a=b; } void main(){ //fun!double; //uncomment for CT error } ---- |
September 11, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timothee Cour | Timothee Cour:
> Currently D will compile templated code that is syntactically correct but
> semantically always incorrect (ie regardless of template parameters), eg
> the following:
> regardless of T, b is not in scope and hence this template cannot be
> instantiated without CT error.
>
> So would it be possible to detect such kind of errors (ie CT error
> regardless of template params) without having to instantiate the template?
There was a discussion about related matters, and there is an enhancement request on this in Bugzilla. Andrei was against it, but lot of other people, me and perhaps Walter too have appreciated the idea.
Bye,
bearophile
|
September 11, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 9/11/13 2:53 PM, bearophile wrote:
> Timothee Cour:
>
>> Currently D will compile templated code that is syntactically correct but
>> semantically always incorrect (ie regardless of template parameters), eg
>> the following:
>> regardless of T, b is not in scope and hence this template cannot be
>> instantiated without CT error.
>>
>> So would it be possible to detect such kind of errors (ie CT error
>> regardless of template params) without having to instantiate the
>> template?
>
> There was a discussion about related matters, and there is an
> enhancement request on this in Bugzilla. Andrei was against it, but lot
> of other people, me and perhaps Walter too have appreciated the idea.
>
> Bye,
> bearophile
I'm not against it, but I find it a very small improvement. Its user base is exactly people who want to write and deploy a template without ever testing it at all, ever. I have a hard time catering to that hypothetical crowd.
Andrei
|
September 11, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On Wednesday, September 11, 2013 15:15:39 Andrei Alexandrescu wrote:
> I'm not against it, but I find it a very small improvement. Its user base is exactly people who want to write and deploy a template without ever testing it at all, ever. I have a hard time catering to that hypothetical crowd.
That crowd deserves whatever bugs they get.
- Jonathan M Davis
|
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | On 9/11/2013 3:15 PM, Andrei Alexandrescu wrote:
> I'm not against it, but I find it a very small improvement. Its user base is
> exactly people who want to write and deploy a template without ever testing it
> at all, ever. I have a hard time catering to that hypothetical crowd.
I'm against it because it makes for a rather bastardized semantic pass - expensive to specify, write and debug, and as you point out of highly suspect merit.
Note that even so, uninstantiated D templates must lex and parse correctly regardless.
|
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Thursday, 12 September 2013 at 05:04:29 UTC, Walter Bright wrote:
> On 9/11/2013 3:15 PM, Andrei Alexandrescu wrote:
>> I'm not against it, but I find it a very small improvement. Its user base is
>> exactly people who want to write and deploy a template without ever testing it
>> at all, ever. I have a hard time catering to that hypothetical crowd.
>
> I'm against it because it makes for a rather bastardized semantic pass - expensive to specify, write and debug, and as you point out of highly suspect merit.
>
Isn't that more or less required already for IFTI ?
|
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On 9/11/2013 10:14 PM, deadalnix wrote:
> On Thursday, 12 September 2013 at 05:04:29 UTC, Walter Bright wrote:
>> On 9/11/2013 3:15 PM, Andrei Alexandrescu wrote:
>>> I'm not against it, but I find it a very small improvement. Its user base is
>>> exactly people who want to write and deploy a template without ever testing it
>>> at all, ever. I have a hard time catering to that hypothetical crowd.
>>
>> I'm against it because it makes for a rather bastardized semantic pass -
>> expensive to specify, write and debug, and as you point out of highly suspect
>> merit.
>>
>
> Isn't that more or less required already for IFTI ?
>
IFTI requires that the signature be analyzed, not the body.
|
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Wednesday, 11 September 2013 at 22:22:46 UTC, Jonathan M Davis wrote: > On Wednesday, September 11, 2013 15:15:39 Andrei Alexandrescu wrote: >> I'm not against it, but I find it a very small improvement. Its user >> base is exactly people who want to write and deploy a template without >> ever testing it at all, ever. I have a hard time catering to that >> hypothetical crowd. > > That crowd deserves whatever bugs they get. > > - Jonathan M Davis *cough* Phobos is that crowd *cough* Seriously. Most new code is tested, however, there is a ton of older code that is not only not-tested, but not even *compiled*: https://github.com/D-Programming-Language/phobos/pull/1514 Not that I'm necessarily *for* said feature, but I think we need to re-evaluate who this "hypothetical crowd" is, before looking down on it. |
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Tudor Andrei Cristian Alexandrescu:
> I'm not against it, but I find it a very small improvement. Its user base is exactly people who want to write and deploy a template without ever testing it at all, ever. I have a hard time catering to that hypothetical crowd.
This is an interesting discussion topic.
Mistakes and bugs are mechanically caught at several different moments, sometimes even before compile-time, thanks to squiggly red lines shown by the IDEs where there's a syntax error. Then bugs are found during compilations, by contracts and unittests at run-time, etc.
If you have a significant amount of template code already written, with unittests, etc, then the small amount of bugs spotted by this enhancement request is not much significant, because at that stage of the development of the code you are supposed to catch the remaining bugs using a high coverage ratio of unittests, etc. So in this case I agree with you this feature is not much useful, or it could even be harmful if programmers trust it too much.
But there is a another situation, when you don't have much new code written. You have just written 5-15 lines of templated code, and you have not yet written unittests on it (I write lot of unittests, but usually after writing the code), at this early stage I think it's useful to have a D compiler that performs simple analysis of the template code, to catch the simple mistakes very quickly. This helps me focus on the less obvious errors, and then I can write the unittests to catch the semantic mistakes of the code.
So I think this feature is not useful the seasoned code you seem to refer to; it's useful to catch as soon as possible silly mistakes inside just written templated code, that allows the programmer to focus on the less obvious bugs and on writing the unittests with high coverage.
Bye,
bearophile
|
September 12, 2013 Re: finding errors with templates without instantiating them | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 9/12/13 9:53 AM, bearophile wrote:
> But there is a another situation, when you don't have much new code
> written. You have just written 5-15 lines of templated code, and you
> have not yet written unittests on it (I write lot of unittests, but
> usually after writing the code), at this early stage I think it's useful
> to have a D compiler that performs simple analysis of the template code,
> to catch the simple mistakes very quickly. This helps me focus on the
> less obvious errors, and then I can write the unittests to catch the
> semantic mistakes of the code.
>
> So I think this feature is not useful the seasoned code you seem to
> refer to; it's useful to catch as soon as possible silly mistakes inside
> just written templated code, that allows the programmer to focus on the
> less obvious bugs and on writing the unittests with high coverage.
I don't buy this. All that work for a fleeting moment. Reminds me of that comedic bit - hands-free sanitizer dispensers are for the fraction of a second between your hand pushing on the button and your hand getting cleaned.
Andrei
|
Copyright © 1999-2021 by the D Language Foundation