On Sunday, May 27, 2018 at 1:22:58 AM UTC+10, Li Jianhua wrote:
>
>
>
> Will C++ do move more often and do copy less often with its specific move 
> semantics. C++ will do move whenever possible, right?
>

Perhaps. It's difficult to tell, because C++ is a horribly complicated 
language. Will C++ use move semantics instead
of copy for smart pointers? Uh, maybe, if your smart pointer meets certain 
conditions ...

As others have pointed out, C++ needs this kind of complexity because with 
references etc the programmer cannot
tell just by looking at the code whether something is a move or copy. In C 
and Go, anything that is a pointer will use
"move" semantics, anything else is "copy". Simple rule, easy to follow, 
easy to see.


Will Golang, C do copy more than C++ because Golang, C don’t have move 
> semantics. So will C++ perform better than Golang, C?
>

Golang will not copy more than C++ unless the programmer wants to. C++ is 
introducing move/copy semantics
because many C++ programmers write code that copies instead of moving 
without the programmer realising it.
The C++ solution is to add another layer of complexity to try and fix it. 
The C/Go solution is to keep it simple so
the problem does not happen in the first place.

Will C++ perform better than Golang, C? That will depend on the programmer, 
not the language. The move/copy
semantics are an example of micro-optimisation, trying to speed up tiny 
bits of the program. Usually it doesn't
matter. Many programs are written in Java, or Python, or JavaScript, where 
programmers almost never think
about move vs copy semantics at all, and those programs are fast enough for 
what they need to do.

cheers,
Hugh Fisher

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to