strcat(target, source)
strcpy(target, source)
But, in SH... cp source target
I feel like these things were developed around the same time, by the same community. I've always wondered if there was a reason for the different perspective. strcat(target, source)
strcpy(target, source)
But, in SH... cp source target
I feel like these things were developed around the same time, by the same community. I've always wondered if there was a reason for the different perspective.Intel:
mov bx, 100
AT&T:
mov $100, %bx
The curious bit is, AT&T assembly syntax does follow this convention so you'll see something like `mov $5, ax'.
expression -> variable; expression memory-location !
to store and memory-location @
to read.Ever notice that for everything in the world that screws, like valves or screws or bottle caps, counter-clockwise loosens and clockwise tightens? How is it we got the whole world to agree on that convention, but software is 50/50 on how we order the source and destination?
"Forward" is also "tighter", apparently.
tar [args] [one thing] [list of things]
it'd be wierd if it was
tar [args] [list of things] [filename]
... but i will admit i frequently make that mistake.
cp [args] [list of things] [destination folder] cp [args] -t [destination folder] [list of things]
The same is true of mv. This is useful if you are piping filenames to xargs. tar [args] [list of things]
where [args] may contain [-f filename], among other things.That is, the destination filename is an optional argument; by default tar outputs to a tape device or stdout, depending on the implementation.
At least in GNU tar, the target filename can very well be specified as the last argument:
tar -c foo.txt bar.txt baz.txt -f stuff.tarFor "mv A B"
I've no problem saying either
mv into A the contents of B
or mv the contents of A into Bhttp://en.wikipedia.org/wiki/Lug_nut#History
Propane tanks also used to have backwards screwing connections. I believe this was a safety 'feature' given the mainstream use of small propane tanks. Having them tighten counter-clockwise prevents similar looking but wrong hoses from being attached to the tank. It also tricked people who didn't understand propane tanks form being able to remove a connection (since they would usually just tighten it further).
Same with some of the LP gas cylinders I have encountered here in Aus.
Why memcpy was parameterized in that order, I am not certain.
lvalue == write location rvalue == read location
It comes from assignment syntax where the left hand side is the target of the assignment and the right hand side is the source. So this makes a ton of sense in C.
OTOH, the Bourne shell was built independent of the C programming language. The Bourne shell inherited a bit from its predecessor the Thompson shell which introduce the concept of command piping. In this case, all operations followed the pattern of data flowing to the right. This is the opposite of how assignment works in all programming languages where data flows to the left.
That's why shell commands generally move data from left to right based on their argument ordering.
FWIW, tar is unique because tar wasn't meant to do archiving to files. If you just did `tar c directory' it would archive the directory to a tape device. The `f' flag is there to redirect the output to a file (instead of the default tape device). So `tar cf foo.tar directory' is not backwards, it just uses an unusual argument convention. The modern form would be `tar --file=foo.tar create directory'.
"cp" is trying mirror how we do things in real life: if you want to take some things from one place and put them in another, you first pick them all up (hence the first argument), walk over to the destination, and then put them down.
*target = source*
Step two is realizing that things don't work that way in C. Step three is sprinkling in semantic sugar to make it work.strcat, then, is for symmetry with strcpy.
* for a slightly smaller definition of everything than in Plan9
mov a,b
as from b to a.