4 ms·
The key is knowing what to use where. Writing certain scripts in Bash is miles more efficient use of time than using python because it's "better". While it's c
by skywhopper 9y ago
The key is knowing what to use where. Writing certain scripts in Bash is miles more efficient use of time than using python because it's "better".
While it's certainly possible to write bad scripts in Bash like the example given, it's just as possible to write bad scripts in Python. All the time spent learning to do bash-like stuff in Python could just as well be spent learning to write better Bash.
I think the readability of the program is key as well. It's interesting that the author never included the full Python program. Based on the snippets I would expect it was longer and was definitely far more verbose. One of Bash's advantages in terms of working with files and shell commands is that most people already know how to work with files and shell commands at the command prompt and so the clarity is already there. If you replace all that with Python library calls all the sudden you're speaking a different language and comprehension will be slower unless your reader works with those Python libs just as often as they use the command line.
In other words, this may all sound good but be careful with this sort of advice. It's often counterproductive to go down this particular path
- binocarlos 9y agoThere are times writing a bash script it feels like "omg - a programming language would be much easier for this task"... So I write a tiny program in the lang of my choice and invoke it from that place in the bash script. The balance between the two tools is great - your advice is spot on for me.
- yes_or_gnome 9y agoI work with a couple people who insistently write shell scripts in Python. I know it's anecdotal, but to me, it's like the metaphor 'When all you have is a hammer, everything looks like a nail.' The scripts use functions liberally, but the code isn't DRY nor self-documented. Written in shell, it would take a fifth of the LOC because there's no need to use subprocess or Popen and parse the output. They're not the best developers, but I certainly trust their Python code than I would trust their shell code. And, there's plenty of work to go around, so it's better than nothing.
- remline 9y agoAs my last project developed, I moved it from simple bash scripts directly to (mostly) python utilities that had their own DSLs.. ansible, supervisord.. I expected to need to look into their source, but given the workarounds in docs and web searches that never seems to need to happen. The resulting configuration is all configuration and not hardcoded paths mixed with Popen and random custom parsing.. I would consider custom python worse than writing bash with too much logic in the cases where you could just exit with a failure. I think the question for your coworkers is what are they reinventing and why do they think a custom remake of it isn't a waste of everyone's time? Further, why do they think they will be more employable after making embarrassing custom internal tools? Compare that to knowing how popular tools work and perhaps contributing something small to one of them or at least being able to answer a question about them.
- kilroy123 9y agoI completely agree. It really depends on how mission critical the script is. One huge advantage with writing it in another language is the ability to write tests for the script.