Go Basics

Go Syntax

Description

Go's syntax is clean and concise. It eliminates many 'ceremonial' tokens found in other languages. For example, semicolons `;` are inserted automatically by the compiler at the end of lines, so you don't type them. Parentheses `()` are not required around `if` or `for` conditions.

Pros & Cons

✅ Pros

  • Readability: Clutter-free code.
  • Strict Compiler: Unused variables cause build errors, keeping code clean.

❌ Cons

  • Rigid: The compiler forces specific styles (e.g., brace placement).

When to Use

Writing any Go application.

Example

Basic syntax elements.

package main

import "fmt"

func main() {
    // Single line comment
    fmt.Println("No semicolon needed at end of line")
    
    /* Multi-line
       comment */
}

Best Practices

Opening braces `{` must be on the same line as the function or statement declaration.

← Go Get StartedGo Comments →