News for hackers. Stuff that matters.
Re:C++ has become a scripting language by tyrion on Wednesday October 16, 2013 @11:45AM (#6560282)
I may be wrong but I think that this is actually spawning a subprocess and thus is not an exact translation of the python example.

This bash script rewritten in python should be something like this:

  import subprocess, sys
  
  inp = open(sys.argv[1], 'r')
  out = open(sys.argv[2], 'w')
  
  sys.exit(subprocess.call('sort', stdin=inp, stdout=out, stderr=sys.stderr))

(I don't know why but it seems that the performance of this version are worse than the original proposed example with writelines/readlines)
Re:C++ has become a scripting language by reirob on Wednesday October 16, 2013 @03:39PM (#6561679)
So what? The Unix Shell library consists of all the executables that are on the system - for me this is the beauty. There is not much of abstraction between the Unix Shell and the system under it. And shell is very tolerant to other programing languages as well - as long as they allow to represent data in text form and through streams or files ;)
Re:C++ has become a scripting language by tyrion on Wednesday October 16, 2013 @05:19PM (#6562216)
Yes, I know that this is the correct way of doing it in bash. I posted this because someone might test the speed of the two scripts and conclude "bash is faster" while they actually measured the speed of "sort" probably.
Re:C++ has become a scripting language by judk on Thursday October 17, 2013 @12:12AM (#6563614)
Microbenchmarks are a distraction. Macrobenchmarks matter.

The real problem with bash is the mess you get when you start needing whitespace or arrays or error handling or non tabular objects or a computation not already implemented as a system program.

Re:C++ has become a scripting language by greyfade on Wednesday October 16, 2013 @12:25PM (#6560531)
It doesn't have to spawn a subprocess. Some shells (like those in Busybox and Toybox) reduce common POSIX userland tools to a function call.
Re:C++ has become a scripting language by robotresearcher on Wednesday October 16, 2013 @12:39PM (#6560618)
Right. And even it was implemented as a subprocess, it's still idiomatic shell code, i.e. what you would Actually Do.