Concept Explanation
Architecture in beginner Go is mostly about separation: put related logic together, keep functions focused, and make files easy to navigate. In this lesson, you will split a tiny program into pieces that make sense, then check whether the structure still feels simple. The goal is to practice organization without overengineering.
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
- Keep each function responsible for one clear task.
- Group related logic so a reader can predict where to find things.
- Use names that describe purpose rather than implementation details.
- Review the structure after changes and remove anything that feels unnecessary.
Step-by-step Guide
- Identify which part of the code handles input, which part handles work, and which part prints output.
- Move one piece of logic into a clearly named helper function.
- Check whether the new structure makes the program easier to read.
- Compare your organized version with the original and explain which is easier to extend.
- End with a quick review: simple flow, clear names, and no extra layers.
Practice Exercises
- Turn a single-file example into two or three focused functions with clear responsibilities.
- Create a small command-line style example where main delegates the actual work to helpers.
- Reorganize a messy example so validation, formatting, and output happen in separate steps.
Coding Challenges
- Design a tiny program structure that can grow without becoming confusing.
- Keep the architecture clean while resisting the urge to create too many abstractions.
Mini Practice Tasks
- Rename one function so its purpose is more obvious.
- Add one new helper that removes duplication.
- Write a one-line note describing why the chosen structure is easier to maintain.
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.