4 ms·
Why is map copy "dst, src" vs "src, dst"?
by throwaway5959 3y ago
Why is map copy "dst, src" vs "src, dst"?
- klodolph 3y agoCopy operations in Go are normally destination first, source second. This includes builtins like copy() and library functions like io.Copy(). Making it "src, dest" would make this one case the opposite of all the others. Note that the order mimics variable assignment. You copy an integer with: var src, dest int dest = src // dest first, src second I appreciate the consistency.
- Xeoncross 3y agoThanks, "mimics variable assignment" is a good way to remember it
- deleted 3y ago[deleted]
- kinghajj 3y agoIt's not that uncommon. https://en.cppreference.com/w/cpp/string/byte/memcpy https://en.cppreference.com/w/cpp/string/byte/memcpy https://en.cppreference.com/w/cpp/string/byte/strncpy https://en.cppreference.com/w/cpp/string/byte/strncpy https://en.wikipedia.org/wiki/X86_assembly_language#Syntax https://en.wikipedia.org/wiki/X86_assembly_language#Syntax
- esprehn 3y agoTo match the semantics of dst = copy(src). Multiple languages model operations like this in assignment order.