stdio performance in tango, stdlib, and perl

Vladimir Panteleev thecybershadow at gmail.com
Thu Mar 22 01:48:59 PDT 2007


On Thu, 22 Mar 2007 01:40:15 +0200, Andrei Alexandrescu (See Website For Email) <SeeWebsiteForEmail at erdani.org> wrote:

> Essentially it's about information. The naive loop:
>
> while (readln(line)) {
>    write(line);
> }
>
> is guaranteed 100% to produce an accurate copy of its input. The version
> that chops lines looks like:
>
> while (readln(line)) {
>    writeln(line);
> }

I'd just like to say that the chosen naming convention seems a bit unintuitive to me out of the following reasons:

1) it seems odd that what you read with readln(), you need to write with write() and not writeln().
2) Pascal/Delphi/etc. have the ReadLn and WriteLn functions, but Pascal's ReadLn doesn't preserve line endings.
3) in my personal experience (of a number of smaller and larger console applications), it's much more often that I need to work with the contents of lines (without line endings), rather than with. If you need to copy data while preserving line endings, I would recommend using binary buffers for files - and I've no idea why would you use standard input/output for binary data anyway.
4) it's much easier to add a line ending than to remove it.

Based on the above reasons, I would like to suggest to let readln() chop line endings, and perhaps have another function (getline?) which keeps them.

-- 
Best regards,
  Vladimir                          mailto:thecybershadow at gmail.com



More information about the Digitalmars-d mailing list