Why is \"slurping\" a file not a good practice for normal text-file I/O, and when is it useful?
For example, why shouldn\'t I use these?
File.read(\'
This is kind of old, but I'm a little surprised that no one makes a mention that slurping an input file makes the program practically useless for pipelines. In a pipeline, the input file might be small but slow. If your program is slurping that means it's not working with the data as it becomes available and rather makes you wait for however long it might take for the input to complete. How long? It could be anything, like hours or days, more or less, if I'm doing a grep or find in a big hierarchy. It could also be designed to not complete, like an infinite file. For example, journalctl -f will continue to output whatever events happen in the system without stopping; tshark will output whatever it sees going on in the network without stopping; ping will continue pinging without stopping. /dev/zero is infinite, /dev/urandom is infinite.
The only time I could see slurping as acceptable would maybe be in configuration files, since the program is probably not able to do anything anyway until it finishes reading that.