Menu
Coddy logo textTech

Naming Conventions

Part of the Fundamentals section of Coddy's GO journey — lesson 13 of 109.

Let's learn about naming conventions in Go, which are important patterns that make our code easier to read.

First, let's see how to name variables using camelCase (starting with lowercase and capitalizing subsequent words):

var userName = "Alex"
const maxLoginAttempts = 3
    
fmt.Println(userName)
fmt.Println(maxLoginAttempts)

After executing this code, we'll see our variable values displayed on the screen:

Alex
3

In Go, we follow these simple naming rules:

  • Use camelCase for variables and functions (like userName)
  • Avoid using snake_case (like user_name)
  • Don't use PascalCase (like UserName) for local variables
  • Important: Names that start with an uppercase letter (like UserName) are exported and visible outside packages

Following these naming conventions makes your Go code more readable and consistent with standard Go practices.

challenge icon

Challenge

Beginner

In this challenge, you'll practice using proper Go naming conventions. You need to fix the variable names in the code to follow Go's standard naming conventions:

  • Use camelCase for variable names (start with lowercase, capitalize subsequent words)
  • Use PascalCase for exported variables (start with uppercase)
  • Avoid using underscores in variable names

Fix the variable names in the code to follow these conventions, then print them.

Cheat sheet

Go uses specific naming conventions to make code readable and consistent:

Variable and function names: Use camelCase (start with lowercase, capitalize subsequent words):

var userName = "Alex"
const maxLoginAttempts = 3

Exported names: Use PascalCase (start with uppercase) - these are visible outside packages:

var UserName = "Alex"  // exported

Avoid:

  • snake_case (like user_name)
  • PascalCase for local variables
  • Underscores in variable names

Try it yourself

package main

import "fmt"

func main() {
	// TODO: Fix these variable names to follow Go naming conventions
	var user_name string = "John"
	var USER_AGE int = 25
	var is_active bool = true
	var FIRST_login string = "2023-01-15"

	// TODO: Fix these variable names to follow Go naming conventions
	fmt.Println("User:", user_name)
	fmt.Println("Age:", USER_AGE)
	fmt.Println("Active:", is_active)
	fmt.Println("First Login:", FIRST_login)
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals