by Amnon · 15y ago · 0 comments
Of course the first syntax breaks when one of the arguments has a space or any other meta-character in it.
To be absolutely clear, I actually like Python. I just strongly disagree with the belief that Python magically ensures readability. Particularly because my impression is that people who think that Python magic pixie dust automatically makes for good code are actually more likely to write bad code. (Because they have not thought deeply enough about what makes code good.)
Therefore I can't agree that the Python that I presented is as good as is possible for a general purpose programming language.
The Python example can be broken down by someone who knows OOP concepts in general, but not Python. It says:
Invoke function Popen on the object subprocess, giving the arguments (for example) 'ls' and '-al' in a list. Standard output should be handled in some way that is indicated by the value of PIPE. On the object returned from Popen, call communicate(), which returns an array; take the first element off that returned array.
Now, in order to make sense of this you would need to know what the arguments to Popen are, what communicate() means and what it returns.
Does that require a trip to the documentation? Yes. Is it less readable? No, it's more readable. The understanding of what was read is not immediately conveyed, however.
The Ruby/Perl/Bash backticks mean nothing even if you have an OO background. Maybe if the command is 'ls' and you know some Unix, you can work it out in your head to understand that it's invoking a command in the shell. What if it's calling something obscure with a string of arcane arguments appended? That will tell nothing, and the backticks will also add zero information.
Backticks are more convenient, but readability is the ability of someone who doesn't know that particular concept, or even that language, to still parse a statement and extract some level of understanding.