Phobos packages a bit confusing

Denis Koroskin 2korden at gmail.com
Tue Dec 1 04:28:30 PST 2009


On Tue, 01 Dec 2009 15:22:23 +0300, Pelle Månsson  
<pelle.mansson at gmail.com> wrote:

> bearophile wrote:
>> Andrei Alexandrescu:
>>> Why not just reuse the same buffer as the previous line? That approach  
>>> is inherently adaptive.
>>  That approach is unsafe. xfile yields byte strings, in D1. When I  
>> write 10 lines long scripts I usually don't need every bit of  
>> optimization, I need the less bug-prone code as possible, because the  
>> thing I have to optimize is my coding time. In D1 strings are mutable,  
>> so if you put them in an AA as keys you must dup them to avoid bugs if  
>> you reuse the same buffer.
>>
>
> You'll have to .dup them if you want to use them as non-views always. I  
> for one like that approach more.
>
> Why call it xfile and not just open?
>
>>> And why is there a need for xstdin vs. xfile? Stdin _is_ a file.<
>>  I use it like this:
>> foreach (line; xstdin) { ... }
>> line is a string with newline at the end.
>> I know this isn't the best design, but it's the most handy for my  
>> purposes. I need to do a limited number of things in those scripts and  
>> iterating over the lines of a fine and over the lines of the stdin are  
>> the only two that matter.
>>  Bye,
>> bearophile

In his notation, xfoo is a lazy version of foo (i.e. it reads file in  
chunks as opposed to reading the whole file at once).

So you are essentially asking, "why file instead of open?". What's the  
difference? It's a bikeshed discussion, but I believe file("filename") is  
more clear than open("filename"). Besides, I'm used to "close" everything  
I "open", which is not suitable here.



More information about the Digitalmars-d mailing list