Go Style: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 16: Line 16:
[[Go_Language#Identifiers_.28Names.29|Identifiers]] should use camel case: <code>SomeColor</code> or <code>someColor</code>, depending on whether they are visible outside the package or not. Do not use snake case <code>some_color</code>.
[[Go_Language#Identifiers_.28Names.29|Identifiers]] should use camel case: <code>SomeColor</code> or <code>someColor</code>, depending on whether they are visible outside the package or not. Do not use snake case <code>some_color</code>.


Naming conventions:
Acronyms should have a consistent case. <code>URL</code> or <code>url</code> is correct, <code>Url</code> is not.
 
Other naming conventions:
* [[Go_Language_Modularization#Idiomatic_Package_Naming_Conventions|Idiomatic Package Naming Conventions]]
* [[Go_Language_Modularization#Idiomatic_Package_Naming_Conventions|Idiomatic Package Naming Conventions]]
* [[Go_Language#Idiomatic_Variable_Naming_Conventions|Idiomatic Variable Naming Conventions]]
* [[Go_Language#Idiomatic_Variable_Naming_Conventions|Idiomatic Variable Naming Conventions]]

Revision as of 19:04, 6 September 2023

External

Internal

Overview

The Go standard library is a good source of code examples, comments and style.

Naming

https://google.github.io/styleguide/go/guide#mixedcaps

Naming is one of the most important aspects of Go development. Writing idiomatic Go requires understanding of its core naming principles.

Identifiers should use camel case: SomeColor or someColor, depending on whether they are visible outside the package or not. Do not use snake case some_color.

Acronyms should have a consistent case. URL or url is correct, Url is not.

Other naming conventions: