[OT] What are D's values?
Tejas
notrealemail at gmail.com
Tue Oct 5 00:51:26 UTC 2021
On Tuesday, 5 October 2021 at 00:11:29 UTC, Paul Backus wrote:
> On Monday, 4 October 2021 at 23:10:27 UTC, Tejas wrote:
>> Can you please list any resources on DbI?
>>
>> I've been finding it pretty hard to grasp, and I only managed
>> to find a few videos by Andrei on the subject.
>>
>> Even the d-idioms website doesn't have much.
>>
>> Any text sources would be really appreciated.
>>
>> Thank you for reading!
>
> Design by introspection is when you have templated code
> "customize" itself based on the specific type(s) it's
> instantiated with.
>
> One place DbI is used a lot is in `std.range`. For example,
> here's how `std.range`'s documentation describes the return
> value of `retro`:
>
>> Type: auto
>>
>> A bidirectional range with length if r also provides a length.
>> Or, if r is a random access range, then the return value will
>> be random access as well.
>
> Source: https://phobos.dpldocs.info/std.range.retro.html#returns
>
> Notice those "if" clauses. The return value has a `.length`
> property **if** the original range, `r`, has a `.length`
> property. That's DbI.
>
> How is it done? Internally, `retro` uses introspection features
> like `__traits` and `is()` expressions to check what properties
> `r` has, and uses `static if` to customize its own
> implementation based on the result of those checks.
Is that seriously all there is to it? I see Andrei saying in his
talks that `static if` doubles the design space covered, that DbI
can tackle combinatorial explosion.
Can DbI really help with software that gets complex exponentially?
I guess a couple case studies will be nice.
I've been putting it off, but maybe it's time I ignore the
"experimental" smell of `checkedint` and `allocator` and actually
study the underlying code.
I'm genuinely having trouble comprehending how a bunch of compile
time queries help reduce the complexity of software constructs
exponentially... (maybe because I'm conflating it with **lines of
code** metric, thinking that DbI will somehow make a 100_000 line
program writable in a couple thousand lines)
More information about the Digitalmars-d
mailing list