std.array.array broken?

Andrej Mitrovic andrej.mitrovich at gmail.com
Sat Feb 1 15:07:07 PST 2014


In reference to this thread:
http://forum.dlang.org/thread/ouyuujnzzvfkvxbfzyak@forum.dlang.org#post-ouyuujnzzvfkvxbfzyak:40forum.dlang.org

Personally I think it was a mistake providing unsafe APIs by 
default. If I would have had it my way, I would introduce:

byLine -> safe, doesn't reuse a buffer
byLineBuffer -> reuses a buffer

That way you get safe-by-default operations for the vast majority 
of users, and a speedy version for those who need it when they 
need it.

This is similar to how the new regex APIs encode in their name 
exactly what they do, e.g. the new matchAll is self-describing 
rather than guessing whether match() has a default mode of "g" 
that matches all or not.

It's probably too late to change byLine now. But warnings and 
notes in the comments have so far been unfruitful. I can't 
imagine many people are aware of warnings, and some warnings are 
so ridiculously long that it makes you question why a function 
was made to have so many caveats. For a classic example, read the 
warnings for toUTFz: http://dlang.org/phobos/std_utf.html#.toUTFz

Safe and simple should be the default, leave the "if 
((cast(size_t)p & 3) && *p == '\0') return str.ptr" wizardry for 
a separately named function that provides these speed benefits at 
the cost of safety.


More information about the Digitalmars-d mailing list