On Mon, 21 Oct 2013 15:02:35 +0100, H. S. Teoh <hst...@quickfur.ath.cx>
wrote:
On Mon, Oct 21, 2013 at 10:40:14AM +0100, Regan Heath wrote:
On Fri, 18 Oct 2013 17:36:28 +0100, Dicebot <pub...@dicebot.lv> wrote:
>On Friday, 18 October 2013 at 15:42:56 UTC, Andrei Alexandrescu wrote:
>>That's bad API design, pure and simple. The function should e.g.
>>return the string including the line terminator, and only return
>>an empty (or null) string upon EOF.
>
>I'd say it should throw upon EOF as it is pretty high-level
>convenience function.
I disagree. Exceptions should never be used for flow control so the
rule is to throw on exceptional occurrences ONLY not on something
that you will ALWAYS eventually happen.
[...]
while (!file.eof) {
auto line = file.readln(); // never throws
...
}
For a file this is implementable (without a buffer) but not for a socket
or similar source/stream where a read MUST be performed to detect EOF.
So, if you're implementing a line reader over multiple sources, you would
need to buffer. Not the end of the world, but definitely more complicated
than just returning a null, no?
R
--
Using Opera's revolutionary email client: http://www.opera.com/mail/