Good name for f.byLine.map!(x => x.idup)?

bearophile bearophileHUGS at lycos.com
Sun Mar 16 10:49:55 PDT 2014


Andrei Alexandrescu:

> A classic idiom for reading lines and keeping them is 
> f.byLine.map!(x => x.idup) to get strings instead of the buffer 
> etc.

This is essentially this issue, I will reopen it if you want:
https://d.puremagic.com/issues/show_bug.cgi?id=4474


> The current behavior trips new users on occasion,

In D the default behaviors should be "not tripping". And the 
optimized behavour should be on explicit request.

So I think byLine should dup on default, and it should not dup on 
request. As I explained in Issue 4474.

Perhaps this breaking change (I asked in Issue 4474) in byLine 
can't happen now.


> and the idiom solving it is very frequent. So what the heck - 
> let's put that in a function, expose and document it nicely, 
> and call it a day.
>
> A good name would help a lot. Let's paint that bikeshed!

A good function name for the copying version is:

"byDupLines"


An alternative solution is the opposite of that I was suggesting 
in Issue 4474:

byLine => not dup

byLine!true => copies every line with dup

Bye,
bearophile.


More information about the Digitalmars-d mailing list