std.digest toHexString
Carl Sturtivant via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 16 13:42:21 PDT 2017
On Thursday, 16 March 2017 at 18:51:45 UTC, Adam D. Ruppe wrote:
> Phobos could have been written to avoid this problem too,
> there's a few solutions that work, but right now, using the
> standard library in a way people expect to work will be
> silently disastrous.
Yes, and as an outsider I find this, well, disconcerting. No
complaint from the compiler about assignment to string of the
result of a library function call should have produced a string
with the obvious semantics.
Having read this thread I have formed a conclusion.
Implicitly slicing rvalue arrays is too much like implicitly
taking the address of an rvalue.
There's an explicit postfix operator [] to do that, and if there
was no implicit slicing, I'd at least know where slicing is
occurring and I wouldn't use the slice of a temporary beyond its
lifetime.
Now a function with a slice parameter could not be called with an
rvalue array parameter without putting an explicit slice operator
in at the point of call.
But writing a function like that is just a way to regard rvalue
arrays of different sizes based upon the same type as being the
same type, when they are not. They are distinct types. And so a
template could take care of that minor syntactic problem if so
desired, with one instantiation for each rvalue array type (i.e.
size), with a ref parameter to avoid copying.
I see every reason to remove implicit slicing of rvalue arrays.
Trying to keep it available sometimes is a complex endeavor, and
the rules will be lengthy, and consequently have more
complications to explain to people joining use of D, and for
what? There's almost nothing to gain. This would be a mistake. D
is already very large.
If I didn't know what my general confidence level in D was for
other reasons, this incident could well have driven me away. The
standard library compiled completely unexpectedly insane and
unsafe semantics when I just called a simple-looking function.
This sort of thing is undoubtedly bringing D into disrepute with
some people here and there, people just trying it out to solve a
problem.
More information about the Digitalmars-d-learn
mailing list