Concept Explanation
This lesson gives you a practical first look at the Go toolchain and the shape of a minimal Go program. You will run a small file, see how package declarations and imports fit together, and understand why Go favors a direct, readable style. By the end, you should be comfortable creating a tiny program, running it from the terminal, and recognizing the basic structure you will reuse in later lessons.
Where to Put the Code
- Define color and position variables at the top.
- Create shape drawing or placement logic in the middle.
- Render output (print, canvas, SVG, or styled block) at the end.
Command Reference
- Run `go version` to confirm that Go is installed and available in your terminal.
- Use `go run main.go` for quick experiments while you are still learning the basics.
- Use `go build` when you want to create an executable and verify the code compiles cleanly.
- Notice how `package`, `import`, and `func main()` define the smallest runnable Go program.
Step-by-step Guide
- Create a new file named `main.go` and type the example yourself instead of pasting it.
- Run the file once and confirm that the terminal prints the expected message.
- Change the printed sentence to something personal so you can verify your edit actually ran.
- Add a second `fmt.Println` line and check that the output appears in the same order.
- Finish by explaining, in one short sentence, what `main()` does in a Go program.
Practice Exercises
- Write a program that prints your name and the word `learning Go` on separate lines.
- Create a version of the example that prints three short status messages in order.
- Make a tiny startup message for a command-line tool, then run it with `go run`.
Coding Challenges
- Deliberately remove the `import` line, run the file, read the compiler message, then fix it.
- Create a clean two-file workspace for experiments and explain which file Go actually runs.
Mini Practice Tasks
- Rename the printed message and rerun the program.
- Add one more output line without breaking the file structure.
- Describe the purpose of `package main` in plain English.
Common Mistake
Mixing x and y axes or using wrong coordinate origin causes shapes to appear in unexpected places.
Real-life Mini Challenge
Draw one square, one triangle, and one circle, then move X marker 2 steps right and 1 step down.