August 16, 2016
On Monday, 15 August 2016 at 14:40:14 UTC, Chris Wright wrote:
> On Mon, 15 Aug 2016 06:43:11 +0000, ZombineDev wrote:
>> Well, I guess it would hard for me to convince you if you don't know what Design by Introspection means.
>
> Some years ago I was on #d on freenode and someone made a reference to high-order functions. I hadn't encountered the term, so I asked about it. The person answered that if I didn't know what it meant, I must not use high-order functions.
>
> In point of fact I was making moderate use of high-order functions at that time, but I hadn't heard that term for it. There is a difference between knowing how to do a thing and knowing a specific term for that thing.

Sorry, I didn't mean my post to sound that way. From my experience of trying to explain DbI to a couple of friends, it's a hard to appreciate the paradigm if you're not already using it casually, and so it would be even harder for me to make a case for why it makes C++ concepts / Rust traits much less useful than they're advertised to be.

The classic example would be walkLength [1]. However that example does not make a good case because it could also be implemented with overloading or dynamic casts (albeit at the cost of inflexibility and/or runtime pessimization) in other languages like C++ and C#. Personally, I really like things like Seb's recent work on attribute propagation for std.experimental.allocator.make and makeArray  [2][3][4], but I'm not sure if that's an example a beginner would appreciate.

[1]: https://github.com/dlang/phobos/blob/v2.071.2-b2/std/range/primitives.d#L1577
[2]: https://github.com/dlang/phobos/pull/4680/files
[3]: https://github.com/dlang/phobos/pull/4682/files
[4]: https://github.com/dlang/phobos/pull/4683/files

August 17, 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.
August 17, 2016
On 2016-08-16 17:08, ZombineDev wrote:

> Swift developers, on the other hand, explicitly state that they don't
> want to support any form compile-time metaprogramming: [5]. Ironically
> they make heavy use of it in their standard-library. However instead of
> writing the meta code in Swift, they use Python [6] for some weird
> variant of .NET's T4 preprocessor templates [7].

Hehe, looks a bit weird. Although they do have some form of language support that looks similar to the version statement in D.

-- 
/Jacob Carlborg
1 2 3 4
Next ›   Last »