Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

which is better "destination, source" or "source, destination"? [closed]

Tags:

copy

api

My question is language transcendent, I've often found prototypes of "copy" functions define parameters in the order: argument1:"destination" then argument2:"source". It is the case of memcpy for example in C. But it is NOT the case of file copy on bash ! You say, e.g.: "$ cp file file2" where file2 is the new file. Which makes much more sense to me, we always say "copy that text here please" and not "copy here that text" which is Yoda-esque.

So the true question is: a good API should use what form (order) ? and maybe another subsidiary question: what form is everybody expecting, if there is any ?

like image 999
v.oddou Avatar asked Aug 13 '11 21:08

v.oddou


2 Answers

I expect source to come first, and destination later.

If you can disambiguate in the language, it would be better. For example, in a OO language:

source.copyTo(destination);

In a language with named parameters:

copy(source: s, destination: d);

The important thing is to make clear what's going on for people reading the code. Code is more often read than it's written.

like image 187
Jordão Avatar answered Nov 15 '22 15:11

Jordão


I've always preferred source-destination (I'm pushing from here to here), but it probably also depends on the call. If it's only 'copy' you're referring to, I think this works. I'm sure there's there are other pull oriented calls that dest-source would apply better to.

like image 35
Adam Wagner Avatar answered Nov 15 '22 15:11

Adam Wagner