Notes — Module 1: Types and Variables¶
These are your personal study notes. Write freely and honestly. Incomplete notes are fine — they show where your understanding still needs work. Return to this file to add insights as they develop over time.
Module: [[go/1. Types and Variables]] Topic: [[go]] Date started: YYYY-MM-DD Status: Not started
Concept Map¶
Sketch how the concepts in this module relate to each other. Fill in the Mermaid diagram.
mindmap
root((Types and Variables))
Basic Types
Integers int int8 int16 int32 int64
Unsigned uint uint8 uint16 uint32 uint64
Floating Point float32 float64
Text string byte rune
Boolean bool
Complex complex64 complex128
Zero Values
Every type has one
Always initialized
No garbage values
Variable Declaration
var with type
var with inference
short declaration :=
Multiple assignment
Blank identifier _
Constants and iota
Typed constants
Untyped constants
const blocks
iota auto-increment
Bit-shift flags
Type Conversion
Explicit only
No implicit coercion
string vs strconv.Itoa gotcha
Alternative: draw this on paper, photo it, and link the image here.
Key Insights¶
The "aha moments" — the things that, once understood, made the rest clear. Be specific: "I finally understood X because Y" is more useful than "X makes sense".
- Zero values are intentional: Add your insight once it clicks — e.g., "I realized that zero values mean I can write
var count intand immediately docount++without a separate setup line." :=is only for locals: Add your insight — e.g., "The:signals declaration; without it,=is just assignment of an existing variable."- Add insights as you discover them
My Understanding¶
Explain the core concepts in your own words, as if teaching them to someone else. If you can't explain it simply, you don't understand it well enough yet.
Basic Types¶
Your explanation here — e.g., "Go has integer types of fixed sizes (int8 through int64) plus platform-dependent int/uint. float64 is what you usually want for decimals. string is UTF-8. byte = uint8, rune = int32 for Unicode. bool is true/false only."
What I'm still unsure about: e.g., "When exactly should I use int32 vs int?"
Zero Values¶
Your explanation here — e.g., "Every variable you declare gets initialized automatically. int → 0, float64 → 0.0, string → empty, bool → false, pointer → nil. You never get garbage."
What I'm still unsure about: e.g., "Does this also apply to struct fields?"
Variable Declaration¶
Your explanation here — e.g., "Three forms: var x int = 1 (explicit), var x = 1 (inferred), x := 1 (shorthand, functions only). := must declare at least one new variable."
What I'm still unsure about: e.g., "When should I prefer var over := in a function?"
Constants and iota¶
Your explanation here — e.g., "Constants are compile-time values. In a const block, iota starts at 0 and increments by 1 for each line. You can use it with expressions like 1 << iota to make bit flags."
What I'm still unsure about: e.g., "Can iota be used outside a const block?"
Type Conversion¶
Your explanation here — e.g., "Go never converts types for you — you must write float64(myInt) explicitly. The big gotcha: string(65) gives 'A', not '65'. Use strconv.Itoa(65) to get the string '65'."
What I'm still unsure about: e.g., "What exactly happens to precision when converting float64 to int?"
Connections to Other Topics¶
How does this module connect to things you already know?
| This module's concept | Connects to | How |
|---|---|---|
| Static types (int, float64, string) | Python (Variables and Types) | Python attaches types to values; Go attaches types to variables. Same idea, opposite direction. |
| Zero values (nil for pointers) | [[go/4. Pointers]] | A nil pointer's zero value means "points to nothing" — dereferencing it panics. |
| iota bit flags (ReadPerm, WritePerm) | [[go/5. Structs and Methods]] | Struct fields often use typed constants for status or mode values. |
| Explicit type conversion | [[go/7. Interfaces]] | Interface satisfaction depends on exact types; conversion matters when implementing interfaces. |
Questions That Arose¶
Log questions as they appear. Don't stop to answer them now — just capture them. Then move the serious ones to QUESTIONS.md.
- e.g., "Why does
intsize depend on the platform? What does that mean for cross-platform code?" → add to QUESTIONS.md - e.g., "Can I do arithmetic between int and float64 directly?" → test in the playground
- e.g., "What happens to iota if I skip a line in a const block?" → might be answered in the module
Code Snippets Worth Remembering¶
Patterns, idioms, or examples that captured something important.
The three declaration forms side-by-side¶
// At package level — must use var
var packageVar int = 10
func example() {
// Inside function — all three forms work
var a int = 10 // explicit type
var b = 10 // inferred type
c := 10 // short declaration
_ = a + b + c // suppress "unused variable" for this demo
}
Why I'm saving this: Seeing all three forms in one place makes it easy to compare. The rule: var at package level, := for most locals.
The strconv.Itoa vs string(n) pattern¶
import (
"fmt"
"strconv"
)
n := 65
fmt.Println(string(n)) // "A" — Unicode code point 65
fmt.Println(strconv.Itoa(n)) // "65" — decimal string representation
fmt.Sprintf("%d", n) // "65" — alternative using fmt
Why I'm saving this: This is the single most common type-conversion gotcha in Go. Muscle memory on this one saves debugging time.
iota bit-shift pattern¶
const (
ReadPerm = 1 << iota // 1
WritePerm // 2
ExecPerm // 4
)
// Combine flags with |, test with &
perms := ReadPerm | WritePerm
hasRead := perms&ReadPerm != 0 // true
Why I'm saving this: The bit-shift iota pattern appears in real Go codebases constantly — HTTP methods, file modes, feature flags, log levels.
What Tripped Me Up¶
Mistakes I made, misconceptions I had, things that confused me more than they should have. Being honest here helps you later.
- e.g., Using
:=at package level — I initially thought:=works everywhere like in Python, but it only works inside functions. It clicked when I remembered:means "new declaration," which only makes sense in a local scope. - e.g.,
string(int)confusion — I expectedstring(65)to give"65". It gives"A". The rule:string()on an integer treats it as a Unicode code point. Usestrconv.Itoa()for numbers. - Fill in your own stumbling blocks as you work through the material.
Summary in My Own Words¶
Write a 3–5 sentence summary of this entire module without looking at any notes. If you can't do this, you need more study time.
Your summary here — write it after completing the module.
Last updated: YYYY-MM-DD