Thread overview | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
March 16, 2014 Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
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 |
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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
Maybe `byUniqueLine`.
We might also consider a higher order range (say, `byUnique`, in the same vein) that GC-clones elements in some generic fashion, then showing `f.byLine().byUnique()` front and centre in `byLine`'s documentation.
Just a couple of half-assed ideas to get the ball rolling.
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | 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. |
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On 3/16/14, 10:28 AM, Jakob Ovrum wrote:
> 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
>
> Maybe `byUniqueLine`.
No, looks like uniq.
Andrei
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On Sunday, 16 March 2014 at 17:28:46 UTC, Jakob Ovrum wrote:
> 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
>
> Maybe `byUniqueLine`.
>
> We might also consider a higher order range (say, `byUnique`, in the same vein) that GC-clones elements in some generic fashion, then showing `f.byLine().byUnique()` front and centre in `byLine`'s documentation.
>
> Just a couple of half-assed ideas to get the ball rolling.
f.byLineIdup();
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 3/16/14, 10:49 AM, bearophile wrote:
> So I think byLine should dup on default, and it should not dup on
> request.
That will not happen.
Andrei
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | 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
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to sclytrack | On Sunday, 16 March 2014 at 17:50:41 UTC, sclytrack wrote:
> f.byLineIdup();
If we can't find a descriptive name, what exactly are we buying over the status quo? Seems like the definition of a trivia function.
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On 3/16/14, 10:52 AM, Jakob Ovrum wrote:
> On Sunday, 16 March 2014 at 17:50:41 UTC, sclytrack wrote:
>> f.byLineIdup();
>
> If we can't find a descriptive name, what exactly are we buying over the
> status quo? Seems like the definition of a trivia function.
A function to send people to, instead of explaining an idiom.
Andrei
|
March 16, 2014 Re: Good name for f.byLine.map!(x => x.idup)? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | On 3/16/14, 10:52 AM, Jakob Ovrum wrote:
> Seems like the definition of a trivia function.
Trivial + frequent = good
see assert, enforce, ~, and many others.
Andrei
|
Copyright © 1999-2021 by the D Language Foundation