Home >Backend Development >Golang >Compare golang function naming convention with other programming languages
Go function naming follows the camel case naming method starting with a lowercase letter, and uses verb phrases to describe the function, such as func WriteToFile(). Compared with other programming languages, Java uses Pascal notation, C uses underscore delimitation, Python and Ruby also use underscore delimitation (Ruby is an exception), and JavaScript uses camel case nomenclature (the first letter can be capitalized).
Go function naming convention compared with other programming languages
In Go, function naming follows the following convention:
func MyFunction()
func WriteToFile(filename string, data []byte)
The following are some practical exercises Case:
// file: main.go package main import "fmt" // Hello prints a greeting message func Hello(name string) { fmt.Printf("Hello, %s!\n", name) } func main() { Hello("World") }
Comparison with other programming languages:
Naming Convention | |
---|---|
Java | Pascal nomenclature (the first letter of each word is capitalized)|
C | Start with a lowercase letter, and use underscores to separate words|
Python | lowercase Starting with a letter, words are separated by underscores|
Camel case nomenclature (but the first letter can be capitalized) | |
Start with a lowercase letter, and separate words with underscores (but phrases such as can/can't can be together) |
The above is the detailed content of Compare golang function naming convention with other programming languages. For more information, please follow other related articles on the PHP Chinese website!