On 10/31/14 5:01 PM, Walter Bright wrote:
On 10/31/2014 12:07 PM, H. S. Teoh via Digitalmars-d wrote:
On Fri, Oct 31, 2014 at 12:04:24PM -0700, Walter Bright via
Digitalmars-d wrote:
On 10/27/2014 12:42 AM, Benjamin Thaut wrote:
I'm planning on doing a pull request for druntime which rewrites
every toString function within druntime to use the new sink
signature. That way druntime would cause a lot less allocations which
end up beeing garbage right away. Are there any objections against
doing so? Any reasons why such a pull request would not get accepted?
Why a sink version instead of an Output Range?
To allow toString to be a virtual function, perhaps?
Output ranges can be virtual functions. All an output range is is a type
with a "put" method.
He said "toString" not "sink". And there are more use cases than a type
that implements 'put'.
What I object to with the sink design is there is no consistency in
design - we cannot preach ranges as a best practice and then use some
other methodology.
Keep in mind that saying "toString will take output ranges" means that
ALL toString implementers must handle ALL forms of output ranges. It's
not an issue with "we don't know what we're doing", it's an issue of
"let's not make everyone who wants to spit out a simple string handle 5+
different use cases, and you'd better test for them, because the
compiler won't complain until it's used!"
I think toString should be first and foremost SIMPLE. It already was --
return a string. But that forces people to allocate, and we want to
avoid that. Using a sink is pretty much just as simple.
BTW, just to be clear, I applaud fixing druntime to remove unnecessary
GC allocations, and agree that with proper design most of the
allocations can go away. It's just that sink and output ranges are both
designed to solve the same problem in pretty much the same way. The
difference appears to be little more than tomayto tomahto.
It is a huge difference to say EVERYONE who implements toString will
take any templated type that purports to be an output range, vs giving
one case to handle.
-Steve