Fact checking for my talk

Chris Wright via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 16 18:50:45 PDT 2016


On Tue, 16 Aug 2016 10:24:38 +0000, Kagamin wrote:

> On Monday, 15 August 2016 at 14:40:14 UTC, Chris Wright wrote:
>> You still haven't defined the term "design by introspection". Some
>> searching around says it's the pattern of:
>>
>> template Foo(T) {
>>   static if (is(typeof(T.bar)) {
>>     // preferred implementation takes advantage of T.bar
>>   } else {
>>     // alternate (also correct) implementation
>>   }
>> }
>>
>> For instance, if T is an allocator and it has a `realloc` method, the
>> preferred implementation, which uses `realloc`, will be chosen.
>> Otherwise, the alternate implementation (which might use a linked list
>> to avoid reallocating) will be chosen.
> 
> Strategy pattern at compile time.

Chosen by type introspection, specifically. I rarely need to implement 
the strategy pattern, and when I do I want to choose the strategy at 
runtime. But I see how it's useful in Phobos.

I don't think it's the sort of feature that will strongly drive adoption 
and make other languages jealous, but it's built in an obvious way on top 
of general-purpose language features, and the fact that these features 
are available and as powerful as they are is awesome.


More information about the Digitalmars-d mailing list