iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

Intro

Go is a small, statically typed language built for servers. Fast compile, simple syntax, opinionated tooling, and great concurrency.

Go — what it is

EXAMPLE
// ===== The values =====
// - Small spec, easy to read across teams
// - Static typing without ceremony
// - Built-in concurrency (goroutines + channels)
// - Excellent standard library (net/http, encoding/json, testing)
// - Single binary deploys, no runtime to ship

// ===== Hello, world =====
package main

import "fmt"

func main() {
    fmt.Println("hello, world")
}

// Build + run:
//   go run .
//   go build -o app && ./app

// ===== A tiny HTTP server =====
package main

import (
    "encoding/json"
    "net/http"
)

func main() {
    http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("content-type", "application/json")
        json.NewEncoder(w).Encode(map[string]any{"ok": true})
    })
    http.ListenAndServe(":8080", nil)
}

// ===== Goroutines + channels =====
package main

import (
    "fmt"
    "sync"
)

func main() {
    var wg sync.WaitGroup
    out := make(chan int)

    for i := 0; i < 5; i++ {
        wg.Add(1)
        go func(n int) {
            defer wg.Done()
            out <- n * n
        }(i)
    }
    go func() { wg.Wait(); close(out) }()
    for v := range out { fmt.Println(v) }
}

// ===== When Go wins =====
// - APIs and microservices
// - CLI tools (single binary, cross-compile)
// - Networking + concurrency
// - Replacing Python services that need speed

// ===== When Go hurts =====
// - Heavy generic algorithms (improving with generics, still verbose)
// - GUI / desktop (immature ecosystem)
// - Data science (Python wins here)

// ===== Patterns to internalise =====
// - Errors as values; if err != nil { return err }
// - Small interfaces; satisfy implicitly
// - go fmt + go vet + staticcheck on save
// - context.Context as the first param of any I/O function

// ===== Pitfalls =====
// - Goroutines without bounded concurrency -> resource exhaustion
// - Ignoring err -> silent failures
// - Slice gotchas (shared backing arrays)
// - Capturing loop variables in closures (Go 1.22+ fixed; still appears in older code)

Why it matters

Go is a no-nonsense server language. Small spec, fast compile, single-binary deploys, first-class concurrency. The idioms (errors as values, small interfaces, context everywhere) are easy to learn and scale to large teams without much drift.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
// Go is statically typed, compiled, garbage-collected.
// Designed at Google in 2007 for fast servers and tooling.
Try it Yourself »

Exercise

Print Hello to stdout.

fmt. ("Hello, Go")

Test yourself

Q1. Go was originally designed at…
Q2. Go is…
Q3. Go has built-in support for…

Discussion

Loading…