TutorialsPreview
Build with AIBuildbeginner8 min

Build a program with AI

Direct a model to write idiomatic Go — and review the error handling it likes to skip.

You will build

A small Go program produced under your direction.

You will learn

Go’s explicit-error idiom, the prompt that gets idiomatic code, and what to check.

Prerequisites

A coding assistant. Go installed to run it, or read along.

The idioms you must recognise

  • Errors are values, returned explicitly and checked — not exceptions. Watch for a model dropping the err return.
  • Code lives in a package; execution starts at func main() in package main.
  • gofmt is non-negotiable — idiomatic Go is formatted Go.

The prompt

Write a Go program that reads a number from the command line and prints its square.
Constraints:
- package main with func main().
- Parse the argument with strconv.Atoi and handle the error explicitly.
- If the argument is missing or not a number, print a clear message and exit non-zero.
- gofmt-clean, no unused imports.
Output a single main.go and the command to run it.
Paste into your assistant

Review what it writes

Review rubric

Tutorial

Learn the basics directly

The Learn tab writes the program by hand. Come here to direct it.

Concepts covered · 1

More like this

Y
Build·beginner·12 min

Your first Python program

Python reads almost like English. Write a small converter, see its output, and open the project in /code to keep editing.

Y
Build·beginner·14 min

Your first C++ program

C++ trades a little ceremony for a lot of speed and control. Write a first program, learn the compile-then-run cycle, and open it in /code.

B
Build·beginner·10 min

Build your first web page

Hand-write a small, semantic page — a heading, a paragraph, a list — then open the same project in /code and make it yours.

Liked this one?

Pass it on

Discussion

Be the first to ask

Your questions stay private with the team. We can pin answers to share with everyone.

Sign in to ask a question privately on this tutorial.

Sign in

No pinned answers yet for this tutorial.