Making the best CLI programs - Programming On Unix
z3bra
If you intend to use awk, you shouldn't use any other tool, as it is a full blow programming language:
Code:
$ weather | awk '{if (NR!=1) {print $5}}'

The point here was to discuss CLI programs, while awk is a language interpreter. That would be like using python or perl to filter the output.
jaagr
(02-06-2016, 03:27 AM)z3bra Wrote: If you intend to use awk, you shouldn't use any other tool, as it is a full blow programming language

This way of thinking is what's wrong with big parts of development communities.
z3bra
Why so? Because you shouldn't "force yourself" and simply use what's available? It makes sense to do so. My point was more about the fact that using awk only to print specific columns is not efficient at all. We came to a point where people use awk ONLY for this specific purpose. That's what is bugging me there.
venam
I've found a nice addition to this topic:
A series of posts about CLI design.
jkl
Edit. :)
venam
(14-09-2016, 02:03 PM)jkl Wrote: Well done after I have posted it in another topic.
I crawl the web faster than spiders.
☆*・゜゚・*\(^O^)/*・゜゚・*☆

EDIT: It deals with the programming aspect of the CLI and other stuffs I've completely missed in the talk but that were mentioned in the discussion here.

Also, this topic is always recurrent, the usual "no news is good news".
Pranomostro mentioned it:
(28-05-2016, 10:50 AM)pranomostro Wrote: I heard an interesting idea a while ago, namely that 3 standard files are not enough.
stdin, stdout and stderr all have distinct purposes.

But very often stderr is misused for status information which doesn't have anything to do with errors.

The author gave a proposal of two other standard file descriptors: usrin and usrout, which can be used for user in- and output
while the program is running. If somebody here knows pick(1), he/she knows the truth (pick lets you select the lines that get sent
down the pipeline):

Some ugly hacking with the tty has to be done.

Here is the medium rant (only read the first half, the second one is about images in the terminal): https://medium.com/@zirakertan/rant-the-...45bb29dac8

I liked the first half. The second is totally infected by "Integrate everything."
And the post author in this section.
Obviously, this goes along with the textuality of Unix-like systems, you want to be able to join together the programs and not mess up the output, make it as simple as possible and easy to parse.

Here's more:
A Guidelines for Command Line Interface Design which discusses in depth the generic view of CLI, the what they are and so what they should do to make it easier, directly leaking from the definition.
A typical answer to what a Unix CLI should adhere to. This is the usual boring stuffs but if you haven't gone through it check it out.
The unfamous Program design in the UNIX environment which discusses the philosophy and generic design of Unix programs. This is more of a styling guide, an analysis of trends that should be avoided or favored.
venam
This article was on HN.
apk
check out venams hit new single

"i crawl the web faster than spiders"

get it on itunes and the play store today k

emerging underground artist guys
acg
(12-10-2016, 12:52 AM)venam Wrote: This article was on HN.

That's a good post, it's been some time since I stopped checking HN daily. Wonder how you found something relevant.
pranomostro
(04-06-2016, 05:01 AM)z3bra Wrote: Why so? Because you shouldn't "force yourself" and simply use what's available? It makes sense to do so. My point was more about the fact that using awk only to print specific columns is not efficient at all. We came to a point where people use awk ONLY for this specific purpose. That's what is bugging me there.

To come back to this: I think there is a reason why we have small programming languages as filters, sed, awk, heck, even regular expressions are a small language. Yes, using awk just to print columns means not using it's full capabilities, but I think that is okay. In the book 'The Awk programming language' the authors stated that awk was mostly used for quick one-liners, and then continued to say that it was also possible to write full-blown programs in it. So first purpose was really a tool for flexible one-liners.

And if you mean efficient in the sense of 'awk is not fast', I want to discuss that with you. Because I had a really hard time beating
a awk 4-liner with a optimised and specialized C program. awk is fast. Give it a try yourself and try to beat awk with C. I found it very hard.

awk is useful for simple tasks like printing columns, validating data and so on, for creating filters on the fly. In my opinion it plays well together with the rest of the environment.

I took a look at my history to show that awk can be really useful for that:

Code:
$ ./leyland | awk '{ print($2"^"$3"+"$3"^"$2"=="$1) }' | bc | g -v '^1$'
# this is a good example for awk's usage: rearranging fields and verifying a commands output
$ zcat data/test06.gz | ./genin | ./rcn | awk '$3<0.5'
# again, we use awk as a filter. sed would be too complicated here, and bc just doesn't cut it (mainly because of the lack of -e)
$ ./ffstats bzip2 test/*.png | awk '$1>1 { print($1*10) }'  | sed 's/\..*//' | stag
# filtering and transforming the input would have been quite tedious in C, at least more than here




Members  |  Stats  |  Night Mode