The Case Against Autodecode

Seb via Digitalmars-d digitalmars-d at puremagic.com
Mon May 30 07:35:03 PDT 2016


On Monday, 30 May 2016 at 12:59:08 UTC, Adam D. Ruppe wrote:
> On Monday, 30 May 2016 at 12:45:27 UTC, Andrei Alexandrescu 
> wrote:
>> That's... what I said. -- Andrei
>
> You said "not arrays", he said "not ranges".
>
> So that just means making the std.range.primitives.popFront and 
> front add a constraint if(!isSomeString()).
>
> Language built-ins still work, but the library rejects them.
>
>
> Indeed, we could add a deprecated overload then that points 
> people to the other range getter methods (byCodeUnit, 
> byCodePoint, byGrapheme, etc.)... this might be our migration 
> path.

That's a great idea - the compiler should also issue deprecation 
warnings when I try to do things like:

string a  = "你好";

a[1]; // deprecation: direct access to a Unicode string is highly 
error-prone. Please specify the type of access. More details 
(shortlink)

a[1] = "b"; // deprecation: direct index assignment to a Unicode 
string is ...

a.length; // deprecation: a Unicode string has multiple 
definitions of length. Please specify your iteration (...). More 
details (shortlink)

...

Btw should a[] be an alias for `byCodeUnit` or also trigger a 
warning?


More information about the Digitalmars-d mailing list