The Case Against Autodecode

H. S. Teoh via Digitalmars-d digitalmars-d at puremagic.com
Tue May 31 13:47:43 PDT 2016


On Tue, May 31, 2016 at 10:38:03PM +0200, Timon Gehr via Digitalmars-d wrote:
> On 31.05.2016 21:51, Steven Schveighoffer wrote:
> > On 5/31/16 3:32 PM, H. S. Teoh via Digitalmars-d wrote:
> > > On Tue, May 31, 2016 at 02:30:08PM -0400, Andrei Alexandrescu via
> > > Digitalmars-d wrote:
> > > [...]
> > > > Does walkLength yield the same number for all representations?
> > > 
> > > Let's put the question this way. Given the following string, what
> > > do *you* think walkLength should return?
> > 
> > Compiler error.
> > 
> > -Steve
> 
> What about e.g. joiner?

joiner is one of those algorithms that can work perfectly fine *without*
autodecoding anything at all. The only time it'd actually need to decode
would be if you're joining a set of UTF-8 strings with a UTF-16
delimiter, or some other such combination, which should be pretty rare.
After all, within the same application you'd usually only be dealing
with a single encoding rather than mixing UTF-8, UTF-16, and UTF-32
willy-nilly.

(Unless the code is specifically written for transcoding, in which case
decoding is part of the job description, so it should be expected that
the programmer ought to know how to do it properly without needing
Phobos to do it for him.)

Even in the case of s.joiner('ะจ'), joiner could easily convert that
dchar into a short UTF-8 string and then operate directly on UTF-8.


T

-- 
Just because you survived after you did it, doesn't mean it wasn't stupid!


More information about the Digitalmars-d mailing list