Which is better "destination, source" or "source, destination"?

My question is a transcendental language, I often found that the prototypes of the copy functions define the parameters in the order: argument1: "destination" then argument2: "source". This applies to memcpy, for example, in C. But this is not the case of copying a file to bash! You say, for example: "$ cp file file2", where file2 is the new file. Which makes sense to me, we always say “copy this text here, please,” rather than “copy this text here,” which is Yoda-esque.

So the true question is: a good API should use which form (order)? and perhaps another supporting question: what form expects everyone, if any?

+6
source share
2 answers

I expect the source to be first, and later -.

If you can eliminate bilingualism in this language, it would be better. For example, in OO:

source.copyTo(destination); 

In a language with named parameters:

 copy(source: s, destination: d); 

It is important to understand what happens to people reading the code. Code is more read than written.

+3
source

I always preferred the source destination (I push from here to here), but it probably also depends on the call. If this is only the “copy” that you are talking about, I think it works. I am sure there are other call-oriented calls that would best apply to dest-source.

0
source

Source: https://habr.com/ru/post/894994/


All Articles