Member-only story
GO Newbie Details
- Left brace
{
cannot be placed on a separate line
In most other languages, the position of {
is up to you. Go is special and follows the rules of automatic semicolon injection: the compilation will add a ;
to the end of each line of code to separate multiple statements, such as adding a semicolon after )
:
- Unused variables
If you have unused variables in the function body code, you cannot pass compilation, but it is possible to declare global variables but not use them.Even if the variable is declared and assigned a value to the variable, it still cannot pass compilation, it needs to be used somewhere:
- Unused imports
If you import a package, but none of the variables, functions, interfaces, or structs in the package are used, compilation fails.You can use the _
underscore as an alias to ignore imported packages to avoid compilation errors, which will only execute package's init ()
.
- Use short declarations to repeat variables
It is not possible to use a short declaration method to repeat the declaration of a variable alone. There is at least one new variable on the left side of : =
to allow multiple variable repeated declarations:
- You cannot use a short declaration to set the value of a field