This is a creation in Article, where the information may have evolved or changed.
When beginners Golang, the use of Liteide on Windows, a lot of grammar can adjust themselves.
Later using the Linux desktop, once again to write, found a lot of things have been forgotten. Is this the habit of gocode after the drawbacks? Or is it the phenomenon of the middle-aged people?
In order not to forget some things, leaving a little footprints, on some of the mistakes made records, and then slowly Add.
About Import,golang is interesting, it allows you to use aliases, but after the alias is enabled, you cannot use the original name! Otherwise, you may experience the following two types of problems
Misuse aliases:
1, error:reference to undefined name ' F '
F.PRINTLN ("Slice definition Test Example:")
Problem point:
When you import "FMT", alias F is not enabled, and alias F is used when applied.
Alias not used:
2. Error:reference to undefined name ' FMT '
Fmt. Println (AVE)
Problem point:
When the import F "FMT", the alias F is enabled, and when applied, the alias F is not used, and the original FMT is still used.
More interesting is that this is the disadvantage of it: it does not allow you to import the extra library, if import is not used, the violent rub you:
3, error:imported and not Used:os
"OS"
Problem point:
Do not allow import of extra packets, if import is not used, error ...
Regarding arithmetic computation, the Golang does not allow the type to be inconsistent, it does not want to do the superfluous thing which does not belong to it (is accustomed to the C language default transformation, here some not accustomed to Oh!) ), inadvertently type inconsistent, may encounter subordinate errors:
Type inconsistency before and after arithmetic operations:
4. error:incompatible types in binary expression
Sum=sum+v
Error:floating point constant truncated to integer
Sum:=3.2+ia
Problem point:
This error can be exploded when the type of sum and V are not uniform when processing operations.
When it comes to function references, if a type is not uniform, you will encounter an error:
5, Error:argument 1 has incompatible type
Ave:=average (XS)
Problem point:
When calling the average function, the occurrence of type inconsistency arises. Func average (xs []float64) (ave float64)
The actual XS is defined as: Xs:=[10]float64 {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.0}
When making a call:
Ave:=average (XS), this will result in type inconsistency, namely: XS is the array name, and function definition is slice, so the correct method to call is: Ave:=average (xs[:])
The disadvantage of Golang is not only that import does not allow superfluous, but also in the definition of variables, and never allow you to define unnecessary variables, once defined, must be used, Duang. Duang. Duang.
6, Error: ' Sum ' declared and not used
Sum:=3.2+ia
Problem point:
variable is defined but not used, which is not allowed.