auto: useful, annoying or bad practice?

Neia Neutuladh neia at ikeran.org
Wed May 2 23:47:58 UTC 2018


On Wednesday, 2 May 2018 at 14:05:49 UTC, H. S. Teoh wrote:
> How else would you do DoI, though?  With Concepts?  The 
> advantage of using structural typing over concepts for DoI is 
> that you would need an exponential number of concepts to catch 
> up with a linear number of optional fields in a structural 
> typing model.  Sure, structural typing has its warts, but it's 
> at least more scalable in this respect.

UDAs to the rescue!

class JackInTheBox
{
   // Which way is it facing?
   Direction front();
   // Pop the box open and have the doll spring out toward the 
front side
   void popFront();
   // Remove everything from the box. Return true if stuff was 
removed.
   bool empty();
}

We're in for a bad time.


@Range
class JackInTheBox
{
   ...
}

Here I just shot myself in the foot.


// A document is a range of pages, maybe.
@Range
struct Document
{
   // saves to disk
   SaveResults save();
}

This is a subtler problem.


struct Document
{
   @Range
   SaveResults save();
}

I shot myself in the foot again.


It's analogous to explicit interface inheritance in C#. Thanks to 
D's options for applying annotations to a block or in label 
style, it wouldn't be terribly onerous.


More information about the Digitalmars-d mailing list