Lazy eval -- an example issue

kris foo at bar.com
Mon Aug 21 21:00:55 PDT 2006


Walter Bright wrote:
> kris wrote:
> 
>> So, we have some existing code for logging. Very efficient, and highly 
>> flexible. It follows the design patterns popularized by Log4J, with 
>> Appenders, Layouts, etc
>>
>> The D version of a logger has five 'levels' of logging:
>>
>> log.trace (char[])
>> log.info (char[])
>> log.warn (char[])
>> log.error (char[])
>> log.fatal (char[])
>>
>> and the intent (with dmd.164) was to add these flavours, specifically 
>> to address the point Walter makes about unnecessary message construction:
>>
>> log.trace (char[] delegate() dg)
>> log.info (char[] delegate() dg)
>> log.warn (char[] delegate() dg)
>> log.error (char[] delegate() dg)
>> log.fatal (char[] delegate() dg)
>>
>> The support code was installed fairly recently, and the above 
>> delegate-wrappers were on the todo list.
>>
>> However, dmd.165 will presumeably not compile this code?
> 
> 
> Correct.
> 
>> Won't there be an overload ambiguity?
> 
> 
> Yes.
> 
>> If so, it illustrates a serious shortcoming in the new syntax
> 
> 
> 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.

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. Why don't you conduct a 
poll asking exactly which 'programmers' won't use the {} delimeters to 
unambiguously declare a delegate?







More information about the Digitalmars-d mailing list