Persistent list

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 15 21:50:04 PST 2015


On Sunday, 15 November 2015 at 19:09:16 UTC, Andrei Alexandrescu 
wrote:
> So one important question is what style we use for Phobos and 
> endorse as idiomatic. My sense after working on this for a 
> while is - forget inout. Qualifiers are rather complex, and of 
> them inout is the most. So I'd rather marginalize it. Please 
> chime in with any thoughts.

Honestly, I'd say that if inout is needed, it should be used, 
since otherwise we're forced to have const results when we should 
be able to get mutable or immutable results.

Now, in many cases, templatizing fixes the problem, but that 
obviously won't work with member functions. For those, if you 
really want to avoid inout, you can always duplicate them, and in 
the case of PersistentList, it's not supposed to work with 
immutable anyway, so duplicating would only mean two copies, but 
if inout lets you do that with one body, it still seems better to 
use inout. Certainly, if you were trying to support mutable, 
const, and immutable, duplicating the function rather than using 
inout would be a bit much.

inout is unwieldy, but it does seem to solve a very real problem, 
and in some cases, the only alternative is writing the same 
function three times with different modifiers, so I would think 
that it would be a good idea to use it when the only alternative 
is needless code duplication.

If we want to revisit inout and try and come up with a better 
solution, then fine, but if it works, then I'd use it until we do 
have a better solution.

- Jonathan M Davis


More information about the Digitalmars-d mailing list