Last modified: Jan 22, 2026 By Alexander Williams

Go Variable Naming Rules for Beginners

Learning to name variables well is a key skill in Go. Good names make your code clear. Bad names make it confusing. This guide covers the rules and best practices.

We will look at the basic syntax, common conventions, and examples. By the end, you will name variables like a pro. If you are new to Go, start with Your First Go Program: Hello World Tutorial.

Why Variable Names Matter

Variables store data in your program. A good name tells you what the data is for. It makes your code self-documenting. Other developers can read it easily.

Go has specific rules for names. Following them keeps your code consistent. It also helps the Go tools work correctly.

Basic Naming Rules

Go variable names must follow these core rules. They are strict and non-negotiable.

A name must start with a letter or an underscore (_). It cannot start with a number. After the first character, you can use letters, numbers, and underscores.

Names are case-sensitive. myVar and myvar are different variables.

You cannot use Go keywords as names. Keywords are reserved words like var, func, and for.

Here are valid and invalid examples.


// Valid variable names
var userName string
var _count int
var totalAmount float64
var isReady bool

// Invalid variable names
var 2ndPlace int    // Starts with a number
var user-name string // Contains a hyphen
var var string       // 'var' is a keyword

Naming Conventions and Style

Rules tell you what you *can* do. Conventions tell you what you *should* do. The Go community follows a style called "Go idioms."

Use camelCase for most variables. Start with a lowercase letter. Capitalize the first letter of each new word. For example, customerName or maxRetryCount.

Use PascalCase for exported names. If a variable (or function) is meant to be used outside its package, start it with an uppercase letter. This makes it "exported."

Keep names short but descriptive. A one-letter name like i is fine for a loop counter. A name like cust is worse than customer.

Acronyms should be all uppercase. Write userID, not userId. Write HTTPClient, not HttpClient.


package main

// unexported (private to package)
var internalCounter int

// Exported (public) variable
var MaxConnections int = 100

func calculateTotal() {
    // local, camelCase variable
    itemPrice := 29.99
    // acronym example
    apiURL := "https://api.example.com"
    // short name for loop
    for i := 0; i < 10; i++ {
        // loop logic
    }
}

Declaring Variables in Go

You declare variables with the var keyword. You can also use the short declaration operator := inside functions.

You can even Declare Variables Without Value in Go (Golang). They get a "zero value" automatically.


package main

import "fmt"

func main() {
    // Standard declaration with type
    var greeting string
    greeting = "Hello"
    fmt.Println(greeting)

    // Declaration with initialization
    var score int = 42

    // Type inference (Go guesses the type)
    var temperature = 36.6

    // Short declaration (inside functions only)
    message := "Welcome!"
    fmt.Println(message, "Score:", score, "Temp:", temperature)
}

Hello
Welcome! Score: 42 Temp: 36.6

Meaningful Names for Different Data Types

Your variable's name should hint at its type and purpose. This is especially helpful with collections like slices.

For a list of strings, use a plural noun. For example, names []string. To learn more, see our guide on Go List of Strings: Create, Iterate, Manipulate.

Use prefixes like is, has, or can for boolean variables. This makes their purpose clear.


package main

import "fmt"

func main() {
    // Boolean with prefix
    var isActive bool = true
    var hasPermission bool = false

    // Integer for counts
    var errorCount int

    // Slice (list) of strings - plural name
    var colors []string = []string{"red", "green", "blue"}

    // Map with descriptive key/value names
    var userAge map[string]int
    userAge = make(map[string]int)
    userAge["alice"] = 30

    fmt.Println(isActive, hasPermission, errorCount, colors, userAge)
}

true false 0 [red green blue] map[alice:30]

Common Mistakes to Avoid

Beginners often make a few simple mistakes. Being aware of them saves time.

Avoid overly generic names. Names like data, value, or temp are not helpful. What kind of data? What is the value for?

Don't use underscores unnecessarily. In Go, underscores in multi-word names (snake_case) are not the standard. Use camelCase instead.

Be consistent. If you start calling something client, don't switch to customer later for the same concept.

Tools to Help You

Go provides great tools. The gofmt tool formats your code automatically. It won't rename variables, but it ensures consistent style.

The govet tool can find some suspicious code, like unused variables. Using these tools is part of writing good Go. Learn more in our Essential Go Tooling Guide.

Conclusion

Good variable naming is simple. Follow the basic rules. Stick to camelCase and PascalCase conventions. Choose clear, descriptive names.

This makes your Go code readable and maintainable. It helps your team and your future self. Practice these rules in every program you write.

Start with simple names. As you build more complex programs, your naming skills will grow. Happy coding!