This is the 9th day of my participation in Gwen Challenge
Why doesn’t Go have a mutable return type?
Covariant Result types refer to the following interface examples:
type Copyable interface {
Copy() interface{}}Copy the code
Is implemented by the following method :(it doesn’t)
func (v Value) Copy(a) Value
Copy the code
At first glance, this seems true because Value implements the empty interface. But in Go, the methods must match exactly. So Value does not implement Copyable. Go separates the concept of a type from its implementation, and if two methods return different types, they are not doing the same thing. Programmers who want to implement Covariant Result Types usually try to express type hierarchies through interfaces. In the GO language, the interface and its implementation should be presented as clearly as possible.
Why doesn’t Go support implicit numeric conversions?
In C, the convenience of automatic conversion between numeric types belies the confusion. When is a value unsigned? What is the value of the number? Will it overflow? Is it standalone and portable when executed? (PS: No. Is the result portable, independent of the machine on which it executes? . It also complicates the compiler; “Normal arithmetic transformations” are not easy to implement in an architecture. So we decided that we had to use some explicit transformations in our code to keep things clear and simple.
A related detail, unlike C, Int is a different type from Int64, even though Int is a 64-bit type. The int type is generic; If you are concerned about the bits held by an INTEGER, we encourage you to specify the specific bits.
A portable B arbitrary C precise D arbitraryCopy the code
Why is Map built in?
And strings for the same reason: they are a powerful and important data structure that provides an excellent implementation and makes programming easier. We believe that GO’s Map implementation is good enough to serve the vast majority of scenarios. If an application could benefit from a custom map implementation, it could write one, but it would not be as convenient as the syntax. That seems a reasonable trade-off.
Tradeoff tradeoffCopy the code