typestar

Variables and constants in Go

Declaration forms, and formatted output.

const MaxUsers = 100

func describe() string {
    name := "typestar"
    var count int = 42
    var ratio float64 = 3.5
    ready := true

    total := count * 2
    return fmt.Sprintf("%s: %d/%d (%.1f) %t",
        name, total, MaxUsers, ratio, ready)
}

How it works

  1. := infers the type; var states it explicitly.
  2. const is fixed at compile time.
  3. fmt.Sprintf formats with %d, %.1f, %t.

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
223
Tokens
49
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 37 seconds.

Type this snippet

Step 1 of 5 in Variables & types, step 1 of 30 in Language basics.

Next →