April 12, 2012
* Nick Sabalausky <SeeWebsiteToContactMe@semitwist.com> [2012-04-11 16:08:05 -0400]:
> "Kevin Cox" <kevincox.ca@gmail.com> wrote in message news:mailman.1599.1334099575.4860.digitalmars-d@puremagic.com...
> >
> >I was wondering why they could not be implied from the code itself.
> 
> That question comes up a lot. The thing is, that would completely defeat the point. The point is that you want the compiler to *guarantee* that certain specific functions are pure/@safe/const/nothrow, etc.
> 
> If you make a change that prevents a function from being pure/@safe/const/nothrow, and the compiler just simply accepted it and internally considered it non-pure/non-whatever, then you haven't gained anything at all. It'd be no different from not even having any pure/@safe/const/nothrow system in the first place. At *best* it would just be a few optimizations here and there.
> 
> But if the compiler tells you, "Hey, you said you wanted this function to be pure/whatever, but you're doing X which prevents that", then you can actually *fix* the problem and go make it pure/whatever.
> 
> 

At any rate, inference would probably end up being more trouble than its worth, or as you said, useless.

Me: "I know this function can throw"
Compiler: "But I don't think so, so I'm gonna mark it nothrow"
Me: "No! You idiot!"
Compiler: "Herp-Derp, code-breaking optimization based on incorrect
assumptions"
Me: "FUUUUUUUUUU...."

I don't trust computers, I've spent too long programming to think that they can get anything right.

--
James Miller
April 12, 2012
"James Miller" <james@aatch.net> wrote in message news:mailman.1640.1334189880.4860.digitalmars-d@puremagic.com...
>
> I don't trust computers, I've spent too long programming to think that they can get anything right.
>

Quote of the year, right there. while(true) vote++;

I need that on a T-Shirt, or tattooed somewhere, or something.


April 12, 2012
On Thu, Apr 12, 2012 at 12:59:06AM -0400, Nick Sabalausky wrote:
> "James Miller" <james@aatch.net> wrote in message news:mailman.1640.1334189880.4860.digitalmars-d@puremagic.com...
> >
> > I don't trust computers, I've spent too long programming to think that they can get anything right.
> >
> 
> Quote of the year, right there. while(true) vote++;
> 
> I need that on a T-Shirt, or tattooed somewhere, or something.
[...]

I'm stealing that quote for my quotes file. :-)


T

-- 
Береги платье снову, а здоровье смолоду.
April 12, 2012
* H. S. Teoh <hsteoh@quickfur.ath.cx> [2012-04-11 22:28:32 -0700]:
> On Thu, Apr 12, 2012 at 12:59:06AM -0400, Nick Sabalausky wrote:
> > "James Miller" <james@aatch.net> wrote in message news:mailman.1640.1334189880.4860.digitalmars-d@puremagic.com...
> > >
> > > I don't trust computers, I've spent too long programming to think that they can get anything right.
> > >
> > 
> > Quote of the year, right there. while(true) vote++;
> > 
> > I need that on a T-Shirt, or tattooed somewhere, or something.
> [...]
> 
> I'm stealing that quote for my quotes file. :-)

I am honored sir.

--
James Miller
April 14, 2012
Le 11/04/2012 22:41, Jonathan M Davis a écrit :
> On Wednesday, April 11, 2012 22:01:36 deadalnix wrote:
>> Le 11/04/2012 00:10, Alex Rønne Petersen a écrit :
>>> I'm planning to go over druntime and add nothrow/pure everywhere I can,
>>> but I don't want to disturb anyone else who's currently working on
>>> patches that this could disrupt.
>>
>> Can't we consider this as an inference issue ?
>
> How so? Attribute inference exists only for templated functions and some
> delegate stuff. We're talking primarily about extern(C) function declarations
> here.
>
> - Jonathan M Davis

As long as the function body is available, inference is possible. If it is possible, it is legitimate to wonder if the problem come from the fact that it isn't done, or that it isn't explicit in the source code.
April 14, 2012
On Saturday, April 14, 2012 15:24:14 deadalnix wrote:
> Le 11/04/2012 22:41, Jonathan M Davis a écrit :
> > On Wednesday, April 11, 2012 22:01:36 deadalnix wrote:
> >> Le 11/04/2012 00:10, Alex Rønne Petersen a écrit :
> >>> I'm planning to go over druntime and add nothrow/pure everywhere I can, but I don't want to disturb anyone else who's currently working on patches that this could disrupt.
> >> 
> >> Can't we consider this as an inference issue ?
> > 
> > How so? Attribute inference exists only for templated functions and some delegate stuff. We're talking primarily about extern(C) function declarations here.
> > 
> > - Jonathan M Davis
> 
> As long as the function body is available, inference is possible. If it is possible, it is legitimate to wonder if the problem come from the fact that it isn't done, or that it isn't explicit in the source code.

But it doesn't work that way, and if it did, the signature of the function could change depending on whether you were using a .di or .d file when importing. D takes the tact that it's better to require that the programmer mark functions as pure - particularly in a language where it's possible to have function declarations with no definitions (it's also easier on the compiler). Attribute inference was only added with templates, because without it, you'd have to duplicate the template for all of the combinations of nothrow, pure, and @safe, which was untenable.

Also, if you're talking about C functions, you _can't_ have the source code. Again, druntime is a prime example of that. Even if the language had attribute inference for all functions, you'd still have to explictly mark C functions as pure for them to be pure, because the compiler doesn't have their source.

- Jonathan M Davis
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home