Phobos usability with text files

bearophile bearophileHUGS at lycos.com
Sun Dec 26 09:56:34 PST 2010


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).

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.

Bye,
bearophile


More information about the Digitalmars-d mailing list