bearophile wrote:
Jarrett Billingsley:
Wow, talk about inefficient.  Consider you have to write out a
100,000 element array.  What a waste of memory.

There are three parameters to consider here: flexibility, speed, and
complexity.

In most situations you don't need speed and flexibility (because you
have to print few data and a comma is OK for most printing
situations), so I think it's better to minimize complexity.

If you need flexibility but speed isn't necessary, use a generator or
list comprehension or a map, plus a join. So the "complexity" is low
still because you don't need to learn more syntax.

Then there is the large data case. Often you need to print it with
commas, so the default printing is fine.

For the uncommon situation you talk about, where you have both large
data and you need flexibility, then write a small for loop with many
write() inside.

-----------------------

Andrei:
How about parsing?<

How about using a module of the standard library designed for such
simple parsing purposes?

std.format. There is formattedWrite that looks and works complementary to formattedRead. About the speed/complexity/flexibility tradeoff, I think it's a good point in spirit but kind of misapplied. I can't bring myself to advocate a solution that involves memory allocation and the such when the task is to dump out an array, and I also need to write and parse sequences all the time, so I extended the formatting strings to make that comfortable and consistent for both parsing and writing. That doesn't preclude using join et al, and also doesn't affect existing code (currently "%(" is invalid), so I don't quite understand the complaint.


Andrei

Reply via email to