On Saturday, 28 December 2013 at 17:42:26 UTC, Jakob Ovrum wrote:
On Saturday, 28 December 2013 at 17:23:30 UTC, Jeroen Bollen wrote:
Usually if you're working with a console though the input stream won't exhaust and thus the blocking 'readln' would be a better option, no?

The blocking behaviour of `stdin` by default is fine. The issue is that `readln` returns an empty string when `stdin` is empty/closed, which is different from an empty line (which is just the line terminator). Approaches that erase the difference with functions like `chomp` can't tell them apart.

Assuming that `stdin` will never close seems like a bad idea when it's so easy to handle, and the consequences of it closing can be harsh (particularly an infinite loop). Even assuming that `stdin` will never be redirected and always used from a console, an experienced user might use ^Z to close standard input to signal a clean end, only to be faced with either an obscure error, segfault or infinite loop.

Wouldn't byline return an empty string if the inputstream is exhausted but not closed?

Reply via email to