Features of Go language

Features of Go language

  1. Compared with the C language, the Go language abandons the habit of using a semicolon as the end of the statement.
  2. Support multiple assignments : statement i, j = j, i can exchange the values ​​of variable i and variable j; functions support multiple return values
  3. Predefined itoa constants, which can be modified by the compiler, are reset to 0 when every const keyword appears, and then before the next const appears, every time iota appears, the number it represents will automatically increase by 1.
  4. Variables, constants, and functions starting with capital letters are visible outside the package (public), variables, constants, and functions starting with lowercase letters are private in the package (private)
  5. The c language does not define the Boolean type, and other languages ​​that provide the Boolean type (such as Go) do not support the conversion between the Boolean type and other data types
  6. Go language supports two character types, one is byte , which represents the value of a single byte of a UTF-8 string; the other is rune , which represents a single Unicode character (although Unicode characters are supported in the standard library, they are actually very few use)
  7. The loop statement in Go language only supports the for keyword, not the while and do-while structures

  1. Go language abandoned a large number of object-oriented features including inheritance, and only retained the most basic feature of composition
  2. In the Go language, variables that are not explicitly initialized will be initialized to the zero value of this type. For example, the zero value of the bool type is false, the zero value of the int type is 0, and the zero value of the string type is an empty string.
  3. Go language clearly tells us the memory layout, and we can adjust the position of the members in the struct to modify the memory layout
  4. Non-intrusive interface : In the Go language, a class only needs to implement all the functions required by the interface, and we say that this class implements the interface. When we implement a class, we only need to pay attention to the integrity of the function itself, not to which interface it should implement. When defining the interface, the user of the interface does not need to care about whether any module implements the interface, and define it according to its own needs. That way, the implementation class and interface will be decoupled
  5. Any type satisfies the empty interface interface{} , so the function of the empty interface interface{} in Go language is equivalent to that of Object in Java
  6. Use the select mechanism to handle channel timeout issues. The characteristic of select is that as long as one of the cases has been completed, the program will continue to execute without considering other cases. So we can execute a goroutine that contains timing functions, and then include it in the select case statement, so as to avoid the permanent waiting problem

Guess you like

Origin blog.csdn.net/a16302010048/article/details/103788566