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

monarch_dodra monarchdodra at gmail.com
Sun Mar 16 12:27:54 PDT 2014


On Sunday, 16 March 2014 at 16:58:36 UTC, Andrei Alexandrescu 
wrote:
> A classic idiom for reading lines and keeping them is 
> f.byLine.map!(x => x.idup) to get strings instead of the buffer 
> etc.
>
> The current behavior trips new users on occasion, 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!
>
>
> Andrei

I'm for it in the sense that : "f.byLine.map!(x => x.idup)" is 
*WRONG*.

It'll allocate on *every* call to front. Pipe it into a filter, 
and you have massive gratuitous memory allocations.

A named function will do better than the sloppy code above. So 
there's my vote...

...or... we could merge my "cache" proposal 
(https://github.com/D-Programming-Language/phobos/pull/1364). 
I'll admit I wrote it with *that* particular case in mind. Then, 
we promote:

"f.byLine.map!(x => x.idup).cache()"

But wait! Now it correct, but *definitly* not nooby friendly. So 
yes, my vote is to have a named function.

On Sunday, 16 March 2014 at 17:51:31 UTC, Andrei Alexandrescu 
wrote:
> On 3/16/14, 10:49 AM, bearophile wrote:
>> A good function name for the copying version is:
>>
>> "byDupLines"
>
> It introduces the notion of "dup" to newbies. I'd rather go 
> with a natural name.
>
> Andrei

There comes a point where you have to learn the language to use 
it. "dup" is an array built-in; it's not ridiculous that expect 
the user to know it.

On Sunday, 16 March 2014 at 18:19:01 UTC, bearophile wrote:
> Once dup/idup become free functions in object you can also 
> write:
>
> f.byLine.map!idup

Indeed, I've been wanting to write this before. IMO, not being 
able to write it is a serious inconsistency.


More information about the Digitalmars-d mailing list