Google Code Jam 2011 Language Usage

Timon Gehr timon.gehr at gmx.ch
Mon May 9 10:43:56 PDT 2011


Andrei Alexandrescu wrote:
> I've implemented readf to be a fair amount more Nazi about whitespace than
> scanf in an attempt to improve its precision. Scanf has been famously difficult
> to use for complex input parsing and validation, and I attribute some of that
> to its laissez-faire attitude toward whitespace. I'd be glad to relax some of
> readf's insistence on precise whitespace handling if there's enough evidence
> that that serves most of our users. I personally believe that the current
> behavior (strict by default, easy to relax) is best.

In my experience readf behavior is not very useful for routine coding tasks that
involve some IO.

If you really need to have very strict requirements about the input format, readf
does not serve you well, because a ' ' still skips all whitespace, a failure to
read leaves the file pointer in an undefined position etc. All carryovers from
scanf. I never want to use scanf when there is a valid chance of invalid input. As
far as I can see, neither readf nor scanf can be used for sophisticated input
validation or parsing of non-trivial input. You have to do it manually. How does
readf make things better with strict(er) whitespace handling?

What behavior is by design, what behavior is caused by bugs? Can you give a
real-world example where readf design clearly beats scanf design? (as it is the
default it should be almost always better, but I fail to see it)

Apart from that, what about the other points I mentioned?

Timon


More information about the Digitalmars-d mailing list