8 ms·
POSIX shell is a bit quirky language and bash add a few quirks on its own, but you can write reasonably working shell code if you'll approach it like any other
by citrin_ru 6y ago
POSIX shell is a bit quirky language and bash add a few quirks on its own, but you can write reasonably working shell code if you'll approach it like any other programming language: learn it (read guides, read man), choose a style guide (or write own), use static analyzers (shellcheck is a great tool), test code on different inputs, ask to review your code.
For some reason it is commonly believed that writing shell so easy that one don't need anything of this. Don't even need to learn it.
- majkinetor 6y agoI guess you can use that approach for pretty much anything in the world. You can totally use it for brainfuck. However, good systems impose elegance without users having to create complex standards around it.
- klapatsibalo 6y agoI agree. However, we had to create complex C "standards" for dos and don'ts in order to _try_ to write safe code. And C is still omnipresent. So there must be some other characteristic of Bash that makes it not fit for this age (or some characteristic of C that makes it irreplaceable, that Bash does not have)
- majkinetor 6y ago> And C is still omnipresent. And actively being replaced by rust each day because those "standards" are obviously not enough. And there is some other characteristic of C - its portable.
- citrin_ru 6y ago1. Yes, but there are little reasons to use brainfuck in production code, and there are reasons to use POSIX shell: 1. It is available on practically all UNIX-like systems from NetBSD to Ubuntu in their default installation (no additional dependencies) 2. For small scripts it can run faster than Python/Ruby/Perl thanks to small startup time. 3. It is a handy tool when all you need a small script which mostly runs other commands/CLI tools (but you still have to spend at least little time to learn it first). May be availability of the shell is an unfortunate historical artifact, yet it still the reason why one may want to use it. 2. Idea to impose elegance upon users is attractive, but even if we ignore that it makes system/language design harder, different people can have different option on what is elegant and what is not. Having said that I like Go (which tries to enforce what can be enforced) because options of its author are not too far from mine. But not everybody is happy with Go and it is not hard to find its criticism.
- majkinetor 6y ago> people can have different option on what is elegant and what is not Thera are also measurable effects of elegant system like number of bugs, questions, libraries, standards, etc.
- citrin_ru 6y agoTo compare say how language syntax/features affect number of bugs, questions, etc you have to make everything else to be equal and it is very hard if possible at all in the real world.