title: Redirection operator vs file handling
body: <p>When writing a simple program for a POSIX-compliant OS which accepts input and produces output, when and why should</p>
  
  <pre><code>myprogram file.in
  </code></pre>
  
  <p>be preffered over</p>
  
  <pre><code>myprogram &lt; file.in
  </code></pre>
  
  <p>and vice versa?</p>
  
  <p>I like the latter because I feel that file handling should be the responsibility of the shell, not my program. On the other hand, I'm not so sure how the same code could work for both files and stdin—shouldn't stdin be interactive, i.e. prompt you for your input? Whereas in a file, the format is understood and predefined, e.g. there is a single integer which is the input value (in which case <em>another</em> option would be to simply accept the value as a command line argument), or each line contains a test case which is a list of space-separated numbers, etc.</p>
  
  <p>Examples would be great.</p>
  
  <p><em>Note that I've already seen <a href="https://stackoverflow.com/questions/6184165/shell-redirection-vs-explicit-file-handling-code">Shell redirection vs explicit file handling code</a> and none of the answers really answered this question in a general sense.</em></p>