Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Why is it good practice for a cli script to take switch args before file list?

by rodion (Chaplain)
on Jul 19, 2006 at 21:24 UTC ( [id://562435]=note: print w/replies, xml ) Need Help??


in reply to Why is it good practice for a cli script to take switch args before file list?

As to why options-first is the standard, it's because in the formative days of Unix, memory wasn't cheap. Neither were the CPU cycles to make a copy of a list of 500 files, or even just to go through them. Unix was exceptional in allowing long command lines, which glob() would fill up in the shell.

It was never necessary, however, to go through the list of files twice. You just process the options and then march on through the list, processing them one at a time. Just once. So long as the options come first, it's a one pass algorithm. If you allow the options to come later, you always have to do an earlier pass to find them, because they can change how you process files earlier in the list.

In the present age of cheap memory and CPU cycles to burn, options-first a leftover convention, now become, ahem, one of the standards. It helps you know where to look for things. (Except when people are following other standards.)

Note that many of the organized and consistent ways of doing things that we all like about Unix come not just from the insight and self-discipline of our technical ancestors, but from external constraints of time and space (memory space). Unix itself started as a reaction to MIT's MULTICS project, the OS that could do most anything, if you could wait a very long time. (That's where the Unix name came from.)

  • Comment on Re: Why is it good practice for a cli script to take switch args before file list?

Replies are listed 'Best First'.
Re^2: Why is it good practice for a cli script to take switch args before file list?
by swampyankee (Parson) on Jul 20, 2006 at 03:12 UTC

    This kind of explains why some compilers and print-oriented utilities intermix switches and file names: they parse them sequentially, and files are only effected by switches that precede them.

    emc

    e(π√−1) = −1
Re^2: Why is it good practice for a cli script to take switch args before file list?
by leocharre (Priest) on Jul 20, 2006 at 15:19 UTC

    Wow that makes a ton of sense.. First the program is provided with the what, then the who... one by one. Thank you so much for the insight!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://562435]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found