3 ms·
That is occasionally true, but in 30 years I've absolutely definitely seen a lot more the other way around, personally speaking. Good POSIX one-liners don't ne
by dahart 8y ago
That is occasionally true, but in 30 years I've absolutely definitely seen a lot more the other way around, personally speaking.
Good POSIX one-liners don't need to change usually and aren't hard to understand. A verbose program, on the other hand only lasts if it's like K&R C with zero dependencies. All the languages and libraries have changed considerably, scripting languages and versions come and go, C++ is quite different and might not compile later, build systems have backward incompatibilities.
Plus, a one liner is, like, one line. It's really not that hard to understand unless it's intentionally crazy, and even then, even if it takes a half hour to work through, that's still less work than something like Knuth's 15 pages of code.
We could be imagining pretty different scenarios, though, so feel free to share examples. Normally a pipe consisting of a combination of sort, cut, head, and uniq is trivial to grok, and it would be very wasteful to re-implement that kind of thing on your own. Here are a few one-liners I've made use of recently that I love:
# count the function calls in log.txt
grep -Po '^\K.+(?=\()' log.txt | sort | uniq -c | tee callcounts.txt
# sum the timings
# input: 2 columns, time & name. output: 3 columns: time_sum, name count, name
# It's basically a pivot table in one line of code
< time.txt perl -lane '$k{$F[1]}+=$F[0]; $c{$F[1]}+=1; END{print "time\tcount\tcall"; print "$k{$_}\t$c{$_}\t$_" for keys(%k) }' | sort -n | tee time_grouped.txt
In my own personal repo, the bash scripts and one liner aliases are outlasting all my python and C++ code. The verbose programs that I wrote myself are harder for me to maintain.