On Sat, 26 May 2018 03:15:45 +0000
Li Jianhua <linu...@outlook.com> wrote:

>   1.  Why does C++ introduce move semantics anyway? What problems is
> it going to solve? 2.  How come Golang, C (Without ++) don’t have
> that move semantics yet? Will they need the move soon?
> 

C++ is a language used among other things for low level performance
critical applications, including microcontroller programming. Some of
these applications do not even have a traditional memory allocator. A
lot of the language is concerned with managing memory allocations and
related issues (constructors and destructors).

Giving the programmer control over move vs copy is useful/necessary in
C++ because of the existence of constructors and destructors. A simple
assignment a = b may cause multiple calls of complex functions that
may do things like obtain database locks etc. Move semantics allow the
programmer to avoid some of these calls in the common situation where a
copy is made and the original is immediately destroyed afterwards. In
this case, instead of constructing a whole new copy with all the
complexity involved, the programmer can arrange for a cheaper move to
be performed instead.

Go on the other hand is a garbage collected language that does not
allow the programmer to manually control allocation, object
construction or deconstruction. Before it would even make remote sense
to give the programmer control over the intricacies of object copying
vs moving there would have to be constructors and destructors added to
Go. For that to happen, probably more than 50% of Go's core team would
have to die.

MSB

-- 
If you do not fear death, how can you love life?

-- 
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