Exceptions to golang function naming convention
In addition to following camel case naming, there are the following exceptions to Go function naming: method functions: start with a lowercase letter, and the receiver type comes first; exported functions: start with an underscore; constructor: start with New, followed by the target type; test Function: starts with Test, followed by the function/method to be tested; anonymous function: has no name and is created through function literals.
Go function naming convention: exceptions
In the Go language, functions are named in camel case, with the first letter lowercase , the first letter of subsequent words is capitalized. However, in some cases, exceptions are made.
1. Method functions
Method functions are functions that belong to a structure, and their naming follows different conventions from other functions. Method function names begin with a lowercase letter, subsequent words have the first letter in uppercase, and the function name is preceded by the receiver type. For example:
type Person struct { name string } // GetName 方法 func (p Person) GetName() string { return p.name }
2. Exported functions
Exported functions are functions that can be accessed through other code outside the package. Their names begin with an underscore (_), indicating that they are exported functions. For example:
func _privateFunction() { // 私有函数 } func _ExportFunction() { // 导出函数 }
3. Constructor
In the Go language, the constructor is a special type conversion function used to convert a type of value into Another type. The name of the constructor begins with New
, followed by the name of the type to be converted. For example:
func NewInt(i int) *Int { return &Int{i} }
4. Test function
In the test file, the name of the test function starts with Test
, followed by the function to be tested or method name. They usually use lowercase camelCase nomenclature. For example:
func TestGetPersonName(t *testing.T) { // 测试 GetPersonName() 方法 }
5. Anonymous functions
Sometimes, you need to use anonymous functions, that is, functions without names. Anonymous functions are created using function literals and cannot be accessed by external code. For example:
func() { // 匿名函数 }
In these exceptions, your function naming should still be clear, concise, and reflect the purpose of the function. Applying these exceptions consistently will help ensure the readability and maintainability of your code.
The above is the detailed content of Exceptions to golang function naming convention. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











session_start()iscrucialinPHPformanagingusersessions.1)Itinitiatesanewsessionifnoneexists,2)resumesanexistingsession,and3)setsasessioncookieforcontinuityacrossrequests,enablingapplicationslikeuserauthenticationandpersonalizedcontent.

MySQL functions can be used for data processing and calculation. 1. Basic usage includes string processing, date calculation and mathematical operations. 2. Advanced usage involves combining multiple functions to implement complex operations. 3. Performance optimization requires avoiding the use of functions in the WHERE clause and using GROUPBY and temporary tables.

Composer is a dependency management tool for PHP, and manages project dependencies through composer.json file. 1) parse composer.json to obtain dependency information; 2) parse dependencies to form a dependency tree; 3) download and install dependencies from Packagist to the vendor directory; 4) generate composer.lock file to lock the dependency version to ensure team consistency and project maintainability.

Methods for configuring character sets and collations in MySQL include: 1. Setting the character sets and collations at the server level: SETNAMES'utf8'; SETCHARACTERSETutf8; SETCOLLATION_CONNECTION='utf8_general_ci'; 2. Create a database that uses specific character sets and collations: CREATEDATABASEexample_dbCHARACTERSETutf8COLLATEutf8_general_ci; 3. Specify character sets and collations when creating a table: CREATETABLEexample_table(idINT

Renaming a database in MySQL requires indirect methods. The steps are as follows: 1. Create a new database; 2. Use mysqldump to export the old database; 3. Import the data into the new database; 4. Delete the old database.

We need Composer because it can effectively manage dependencies of PHP projects and avoid the hassle of version conflicts and manual library management. Composer declares dependencies through composer.json and uses composer.lock to ensure the version consistency, simplifying the dependency management process and improving project stability and development efficiency.

Java is suitable for developing cross-server web applications. 1) Java's "write once, run everywhere" philosophy makes its code run on any platform that supports JVM. 2) Java has a rich ecosystem, including tools such as Spring and Hibernate, to simplify the development process. 3) Java performs excellently in performance and security, providing efficient memory management and strong security guarantees.

JavaplaysasignificantroleinIoTduetoitsplatformindependence.1)Itallowscodetobewrittenonceandrunonvariousdevices.2)Java'secosystemprovidesusefullibrariesforIoT.3)ItssecurityfeaturesenhanceIoTsystemsafety.However,developersmustaddressmemoryandstartuptim
