What's wrong with D's templates?

Walter Bright newshound1 at digitalmars.com
Mon Dec 21 22:30:34 PST 2009


Yigal Chripun wrote:
> On 22/12/2009 05:22, Walter Bright wrote:
>> Kevin Bealer wrote:
>>> The performance / impl-hiding conflict is a fundamental problem -- if
>>> the user's compiler can't see the template method definitions, then
>>> it can't optimize them very well. If it can, then the user can too.
>>> Any method of compiling them that preserves enough info for the
>>> compiler to work with will probably be pretty easily and cleanly
>>> byte-code-decompilable.
>>
>> Absolutely right.
>>
>> One of the features that C++ exported templates was supposed to provide
>> was obfuscation of the template bodies so that users couldn't see it. My
>> contention was that there was essentially no reasonable method to ensure
>> that.
>>
>> 1. any obfuscation method only has to be cracked by one individual, then
>> everyone can see through it.
>>
>> 2. if you ship the library for multiple compilers, you only have to
>> crack the weakest one
>>
>> 3. if you provide the decryption key to the customer, and you must, and
>> an open source compiler is used, you lose
> 
> You can also dis-assemble binary libs. That's not the point of this 
> discussion. The point is having proper encapsulation.

Disassembling is a very different deal, because much information is lost 
in the emission of assembler. But with template bodies, 100% of the 
semantic information must be present.

Proper encapsulation is a convention thing, because if you have the 
source (or can extract it somehow) you can defeat any encapsulation if 
you've a mind to.



More information about the Digitalmars-d mailing list