Lazy eval -- an example issue

Walter Bright newshound at digitalmars.com
Mon Aug 21 23:45:25 PDT 2006


kris wrote:
> Walter Bright wrote:
>> Just get rid of the (char[]) versions. You could argue "what about the 
>> efficiency?"
>>
>> 1) Passing a delegate is exactly the same number of instructions as 
>> passing a char[], i.e., it is two values being passed.
>>
>> 2) Actually calling the dg() will, of course, cost more instructions 
>> than just referencing a []. This is mitigated by, presumably, logging 
>> being normally off, and being overshadowed by the rest of the actual 
>> logging cost.
>>
>> 3) It is possible that the delegate can be inlined, thus eliminating 
>> any extra overhead.
> 
> 
> lol! I can just imagine 1001 log statements inlined within the log code ;D
> 
> There's a fairly significant overhead in making a callback. Just as 
> much, or more, than handling a significant proportion of log-messages 
> themselves (I find a significant number to be static text; not 
> contructed dynamically). In addition, if the compiler can't prove these 
> logging delegate do not escape, each hosting function may well have 
> their frames allocated on the heap ... we've been discussing that just 
> recently.

I've been thinking a lot about the escape problem. I'm pretty sure that:
	char[] delegate() { return "foo"; }
can be detected and so I can assure you it won't cause the enclosing 
function's variables to be allocated on the heap.

> All this because you insist programmers can't be bothered to add a tiny 
> bit of syntax (even optionally) to clarify the intent? This is madness!
> 
> Utter madness. Please restore some sanity here.

Calling it 'madness' is blowing things way out of proportion. (And you 
still can use the { } syntax like before.)

> Why don't you conduct a 
> poll asking exactly which 'programmers' won't use the {} delimeters to 
> unambiguously declare a delegate?

I've struggled to get people to accept the {} version ever since D 
adopted anonymous delegates. Haven't made much headway in getting such 
used or in it having any sort of significant impact. How many have made 
a "dotimes(n, exp)" function or any sort of syntax extension using it? 
None that I've seen.

It's sort of like the itunes. Apple didn't invent anything new. They 
just removed a couple annoying button pushes, and voila, suddenly the 
handheld music player gained traction.

I hesitate to use argumentum ad verecundiam because it's a logical 
fallacy, so you can take the following for what it's worth. Andrei and I 
certainly have our differences of opinion. But when I disagree with him, 
I'd better have done my homework, or I'll get cut to pieces. He thinks 
(and he obviously convinced me) that removing the { } makes all the 
difference.

I want to give it a fair shot. It has potential to be a big win for D, 
and the consequences of it being a mistake are small. How many here have 
experience with defmac in Common Lisp, or something equivalent? I sure 
don't, but people who use CL successfully say it's huge.



More information about the Digitalmars-d mailing list