Dealing with Autodecode

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Tue May 31 19:28:04 PDT 2016


On Tuesday, May 31, 2016 17:46:04 Walter Bright via Digitalmars-d wrote:
> It is not practical to just delete or deprecate autodecode - it is too
> embedded into things. What we can do, however, is stop using it ourselves
> and stop relying on it in the documentation, much like [] is eschewed in
> favor of std::vector in C++.
>
> The way to deal with it is to replace reliance on autodecode with .byDchar
> (.byDchar has a bonus of not throwing an exception on invalid UTF, but using
> the replacement dchar instead.)
>
> To that end, and this will be an incremental process:
>
> 1. Temporarily break autodecode such that using it will cause a compile
> error. Then, see what breaks in Phobos and fix those to use .byDchar
>
> 2. Change examples in the documentation and the Phobos examples to use
> .byDchar
>
> 3. Best practices should use .byDchar, .byWchar, .byChar, .byCodeUnit when
> dealing with ranges/arrays of characters to make it clear what is happening.

The other critical thing is to make sure that Phobos in general works with
byDChar, byCodeUnit, etc. For instance, pretty much as soon as I started
trying to use byCodeUnit instead of naked strings, I ran into this:

https://issues.dlang.org/show_bug.cgi?id=15800

But once Phobos no longer relies on autodecoding except maybe in places
where we can't actually excise it completely without breaking code (and
hopefully there are none of those), then we can look at how feasible the
full removal of auto-decoding really is. IMHO, leaving it in is a _huge_
piece of technical debt that we don't want and probably can't afford, so I
really don't think that we should just assume that we can't remove it due to
the breakage that it would cause. But we definitely have work to do before
we can have Phobos in a state where it's reasonable to even make an attempt.
byCodeUnit and friends were a good start, but we need to make it so that
they're treated as first-class citizens, and they're not right now.

- Jonathan M Davis



More information about the Digitalmars-d mailing list