Live data from Hacker News

I always forget the argument order of the `ln -s` command

reddit.com

81–90 of 127 posts

Re: I always forget the argument order of the `ln -s` command

#81
post #75

Earlier quoted context omitted.

The reason strcat, strcpy have the destination first is because of the need to support a variable number of arguments. By definition, if the number of arguments is variable, they must be at the end. So if you think of sprintf for instance, the destination has to be first. Now, to be consistent, strcat has to behave the same and have the destination first as well, although it doesn't have a variable number of argument…

I'm pretty sure strcpy et al pre-date the introduction of varargs. Besides, there's no reason the format string couldn't be the last argument of printf, except the specific technical detail that C requires at least one mandatory argument in any variadic function (the variable's address is used to locate the optional arguments in the stack.)

On a machine's runtime stack, there is no indication of how many parameters were passed to the function (at least on x86). C functions must use one of the mandatory arguments to determine how many arguments were pushed on the stack. In the case of the printf-family of functions, it's the number of format specifiers, e.g., "%d".

Re: I always forget the argument order of the `ln -s` command

#82
The worst part with that kind of mistakes is that you end up never knowing for sure. :)

You start with "ln -s A B" and realize you always make the mistake, so you force yourself to do the opposite of your natural instinct: "ln -s B A". It works until this becomes natural but you still think you always get it wrong, so start doing the opposite of your new natural: "ln -s A B". You'll now be very confused until you force yourself to learn it for good.

This happens to me all the time for various binary things.

Re: I always forget the argument order of the `ln -s` command

#84
Why don't we have better shells that give hints on these things?

I'm thinking like an IDE will pop up some help text when you begin typing a function name or a recognised special word. Why doesn't the standard sh (bash for me) give me similar help, as I type "ln" it could give me a pop-up with the possible completions and then as I get to "ln -s" it could remind me with "TARGET [NAME] // will create a file named NAME that is a soft link to TARGET, or use TARGET's name if NAME isn't specified". You get the picture.

In a pure text env the help could appear on the next line highlighted appropriately or could be to the right of the cursor or somesuch.

I'm hoping someone will say $CONSOLE does that already ...? Anyone?

Re: I always forget the argument order of the `ln -s` command

#87
post #77

The way I remember it is "ln -s target [filename]", where filename is an optional argument to override the default, where the default is a link created in the CWD pointing to target. Easy.

Yup. The thought process is basically "the target is optional, so it has to go last".

Re: I always forget the argument order of the `ln -s` command

#88
post #54
post #2

I used to have this problem. Then I realized that if I want to really copy a file, I type $cp file_from file_to and that $ln -s link_from link_to has a very similar effect to the cp command above. I haven't messed this up ever since.

In my experience the more variable argument often comes last, presumably for easy reuse. For example... $chown user1 file1 $chown user1 file2 $ln -s file1 file2 $ln -s file1 file3 ...seems more likely than... $chown user1 file1 $chown user2 file1 $ln -s file1 file2 $ln -s file3 file2

That's the reason behind a most of the argument orders in the Haskell standard library: To ease Currying.

Re: I always forget the argument order of the `ln -s` command

#89
post #74

Earlier quoted context omitted.

Which is really the odd ball. In a left-to-right language, it's sort of bizarre that we don't write `4 = x' since the rvalue tends to be the more complicated part of the expression. The curious bit is, AT&T assembly syntax does follow this convention so you'll see something like `mov $5, ax'.

Indeed. Assignment should really look like something like this this: expression -> variable;

Forth uses

  expression memory-location !
to store and

  memory-location @
to read.
Post reply on HN