3 ms·
This is one of those things I always look out for in submissions at work (as bad as that may sound) It's one of the easy ways to guarantee a process will run i
by bravetraveler 5y ago
This is one of those things I always look out for in submissions at work (as bad as that may sound)
It's one of the easy ways to guarantee a process will run into an edge case eventually...
General rule of thumb: when possible, lean on shell features. Globbing, expansion, redirection. That replaces dozens of tools (eg: `seq`, `ls`, `cat`, and so on)
Another example (though less severe) that comes to mind: subshells to simply read (cat) a file.
Unless you're doing things at a ridiculous scale/pace, it doesn't usually matter - but redirection is 'cheaper'.
(Talking about cases where you care about nproc/nofile ulimits)
I wish I could contrive better examples. I feel like my ability to 'sniff' this kind of stuff out is usually what makes my best contributions at work, but without being in the moment... it's difficult.
xargs is a good one. That's usually an indication you need an array, even though I think they're 'fake' in BASH
- wutbrodo 5y agoHonestly, I've yet to hear a good reason not to just use Python for scripting that's any more complex than a series of commands. I resisted this for years, but one day realized I was only doing it because it felt intuitively right that scripts were simple extensions of the way one engages with the terminal interactively. I had to come to terms with the fact that the intuition gap is due to the fact that bash is so dang awful.
- sethammons 5y agoI like that ruby and perl can integrate with shell commands more easily than python or go.
- wutbrodo 5y agoRight, I didn't mean to single out Python, but rather to single out Bash. My comment applies to Ruby and Perl as well.
- bravetraveler 5y agoSadly I'm still there. Largely because... I killed my development mojo as a kid. C/C++ and the early web crazes. Nowadays I'll do most ad-hoc complex things with BASH... but at a certain point I tend to use Ansible. I guess one could say I indirectly write Python through Ansible/YAML :)