October 27, 2015
That is sensible. However, another way to look at it is:

1. "alias this" implements subtyping

2. By using "alias this" with string, DirEntry is subtyping the string type

3. A subtype of a range should be a range

Therefore, DirEntry is a range so the language needs to figure how to treat it as such.

To some extent I'm playing devil's advocate because I foresee the difficulties in making this work.

Andrei

On 10/26/15 5:27 PM, Walter Bright via phobos wrote:
>
>
> On 10/26/2015 9:27 AM, Dmitry Olshansky via phobos wrote:
>> Agreed. That is my opinion as well, however luck of any attention from
>> you and Walter led to the point where we
>> need (a) and (b) to work right now and we hacked it (somewhat of
>> speaking for the community here, correct me if I'm wrong).
>
> My recommendation was to remove the alias this in DirEntry that tried to
> turn it into a string. A DirEntry is not a wrapper for a string, in
> particular, it does not support range primitives, which is why the
> string functions failed when changed to have InputRange parameters.
> Adding range primitives to DirEntry would cause other weird problems,
> because DirEntry is fundamentally not a range (a range 'consumes' its
> data via popFront() which makes no sense for DirEntry).
>
> Yes, that breaks:
>
>      DirEntry direntry;
>      remove(direntry);
>
> which must be rewritten as:
>
>      DirEntry direntry;
>      remove(direntry.name);
>
> and we're not supposed to break existing code. But the alternative,
> which is redoing every template that accepts an InputRange, seems an
> awfully heavy burden. Even if we do this change pervasively in Phobos,
> how does that help anyone else who uses InputRanges?
>
> Tl,dr: the alias this in DirEntry is an abusive bad practice, and should
> never have happened.
> _______________________________________________
> phobos mailing list
> phobos@puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos
October 27, 2015
On Tuesday, October 27, 2015 10:28:25 Andrei Alexandrescu via phobos wrote:
> That is sensible. However, another way to look at it is:
>
> 1. "alias this" implements subtyping
>
> 2. By using "alias this" with string, DirEntry is subtyping the string type
>
> 3. A subtype of a range should be a range
>
> Therefore, DirEntry is a range so the language needs to figure how to treat it as such.
>
> To some extent I'm playing devil's advocate because I foresee the difficulties in making this work.

While I understand that way of looking at it, I think that in this case at least, it would just be cleaner to get rid of the implicit conversion. Personally, I've found it to be very annoying even without the problems that we have here, since it means that dirEntries does horribly with anything involving type inference (including foreach).

And I'd argue that conceptually string is _not_ a sub-type of DirEntry. It's just the only way that we have to implement an implicit conversion. So, while it might be nice in the cases where you explicitly assign or initialize a string with a DirEntry, in pretty much all other cases, you don't want that conversion to take place, and the fact that it exists is just problematic. This would work far better if we had a way to tell the compiler that if the code tries to convert a DirEntry to a string that it should then use the name property of the DirEntry but also tell the compiler that that conversion should not be used in any kind of type inference (so we get an implicit conversion but no sub-typing).  However, we don't have that and instead have the far more blunt (and problematic) alias this.

Honestly, it's issues like this which make it so that I think that using alias this is usually a bad idea. It can work reasonably well when templates and introspection aren't involved, but once they are, alias this tends to break things very quickly.

- Jonathan M Davis

_______________________________________________
phobos mailing list
phobos@puremagic.com
http://lists.puremagic.com/mailman/listinfo/phobos
1 2
Next ›   Last »