Phobos packages a bit confusing

bearophile bearophileHUGS at lycos.com
Mon Nov 30 17:26:20 PST 2009


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.


>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



More information about the Digitalmars-d mailing list