So what does (inout int = 0) do?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 15 10:11:39 PDT 2016


On 04/15/2016 12:19 PM, Kenji Hara via Digitalmars-d wrote:
>
> Didn't you use array.dup until now? It's a good example to handle
> qualifiers with inout.

Would it be difficult to make it work without inout?

> It's not sensible at all, inout is already well-defined and has much
> power in D's type system.
> Removing it is just a foolish idea.

What are a few examples of the power of inout?

What things does inout afford us, that would be otherwise not achievable?

> If you worry the future of Phobos written in D, first you would need to
> think about @safe.
> It's yet not well defined/implemented by compiler, and many Phobos code
> are marked as @trusted.
> Does it has lower priority than complain to a small hack for the
> *current* inout limitation?

The thing about @safe is it does enable things that otherwise would not 
be possible. Overall I agree there are plenty of things that deserve a 
revisit, but just putting in competition things against one another is 
unlikely to shed light on their technical merit.

> I just cannot agree your argument.

I understand and would like to be better informed. So could you please 
substantiate your argument by replying to the questions above?

To restate my arguments:

1. The motivation of inout is clear and simple - have it as a 
placeholder for any other qualifier so as to avoid the method 
duplication observed in C++. However, it has over time grown into a 
feature of which complexity way transcends its small usefulness.

2. Attempting to make inout useful have created their own problems, 
solving which in turn have increased its complexity. This cycle of 
accretions has led over time to a vortex of oddity in the middle of the 
type system.

3. For all problems that inout is purported to solve, I know of idioms 
that are definitely simpler and overall almost as good if not better. So 
a hard question is whether the existence is justified.

There are 306 uses of inout in Phobos. A good thing to do would be an 
investigation of their usefulness.


Andrei



More information about the Digitalmars-d mailing list