On 12/26/10 11:56 AM, bearophile wrote:
Andrei:
But you don't need a new string for each line to evaluate max over
line lengths; the current byLine works.<
Right. There are various different ways to implement that little task
in functional style. But the task requires to print the longest ones.
So you have to filter according to the max length. And if you filter
you consume the iterable (I think). So you need to dup the array
again.
It looks simple, but I have tried to create a new version like that
writing some versions, and I have had several 'access violations'.
This very bad for people that want to write a script with D.
Generally I think buffer reuse in byLine() is too valuable to let
go.
In my post you see I have never suggested to remove buffer reuse.
I have suggested two possible alternatives. In both alternatives the
byLine() is split into two different methods:
First possibility, this is my preferred: 1a) Modify byLine() so it
doesn't reuse the buffer. 1b) Add another method, like byFastLine()
that reuses the buffer.
Alternative: 2a) Keep byLine() as it is now, so it reuses the
buffer. 2b) Add another method, like byDupLine() that doesn't reuse
the buffer.
In the post I have explained the rationale behind this.
I prefer the first possibility because the D Zen says that the more
safe option is the default one, and the faster less safe is on
request (and I agree with this part of the D Zen).
Well the D Zen would attempt to reconcile the two such that the obvious
option is the safest and the fastest.
Let's also not forget that "safe" is a bit abused here - we're not
talking about lack of safety as much as incorrect results.
Maybe a byLine!string() would be the best of both worlds by
automatically calling to!string against each line. That can actually be
nicely extended to e.g. byLine!(double[]) to automatically read lines of
whitespace-separated doubles.
Talking about usability and egonomy in this newsgroups is sometimes a
very tiring job :-) Even very little things seem to require a lot of
work and discussions.
One possible issue is that you start with the assumption you're
unequivocally right in matters that are highly debatable. That sometimes
makes it tiring for the rest of us, too, but I'm not one to complain :o).
Andrei