Living Museum of Learning

Where real moments become exhibits
← Prev Next →
Tianjing Walks Into the Trap

Tianjing Walks Into the Trap

Three hours of iOS chess, one very common programming mistake, and the moment Donald finally felt peaceful

Yesterday, Tianjing and Donald spent nearly three hours building an iOS chessboard.

They had already gone far beyond simply drawing a board. Tianjing was working with a Piece structure containing col, row, rank, and color; a pieces array holding the game objects; touch coordinates converted into board coordinates; and touchesBegan, touchesMoved, and touchesEnded connecting her finger to the program.

She was also learning something much deeper: the screen was no longer just a picture. There was data underneath it, and the program could search that data.

Near the end, Donald asked, “You must be very tired, right?”

Tianjing replied, “还好吧.”

She knew how huge a step they had just made.

The highlight came when they wrote:

func pieceAt(col: Int, row: Int) -> Piece? {
for i in 0..<pieces.count {
if col == pieces[i].col && row == pieces[i].row {
return pieces[i]
}
}
return nil
}

Tianjing understood what the function was supposed to do: search through all the pieces and return the one occupying a particular position.

Then she stepped directly into one of the most classic beginner programming traps.

She put return nil inside the loop:

if col == pieces[i].col && row == pieces[i].row {
return pieces[i]
} else {
return nil
}

Her reasoning was completely natural: if this piece isn't the one we're looking for, then there is no match.

But the for loop had a different meaning.

Failing to match this piece does not mean failing to match all the pieces.

The function had to keep searching.

Most beginners fall into this trap at least once. 😂

What mattered was not that Tianjing made the mistake. What mattered was that she understood exactly why it was wrong.

Once she got it, Donald felt more peaceful.

The next day, Donald deliberately slowed things down.

After yesterday's nearly three-hour push, Tianjing had a one-hour class and started a similar project: Chinese chess.

She had no difficulty adapting yesterday's board-centering idea to the new geometry. The Chinese chess board became 8 cells wide and 9 cells high, with the river creating the gap in the vertical lines.

When the frame was ready, Donald gave her the piece images.

Tianjing put the first piece on the screen.

It was technically not on the board yet — it appeared at (0, 0) — but Donald and Tianjing both knew what would happen next.

They ended the class.

There was no need to spend another hour finishing something they both already knew she could finish.

Yesterday, she had discovered the trap.

Today, she had demonstrated that she could carry what she had learned into a new problem.

A programming loop is not merely a way to repeat an instruction. It changes the meaning of a decision.

Inside a search:

“This item doesn't match” means keep looking.
“I found a match” means return it now.
“Nothing matched” can only be concluded after the whole search is finished.

Tianjing experienced this distinction rather than merely being told about it.

She also began to transfer ideas instead of memorizing solutions. The Chinese chess board was different from the 8×8 chessboard, but the underlying ideas — coordinates, dimensions, centering, drawing, objects, and eventually searching for objects — could travel with her.

Perhaps the most important learning was less technical: after a huge breakthrough, learning does not always need another huge breakthrough.

Sometimes the right next step is simply to slow down.

A beginner can move from drawing pixels to thinking in terms of objects, coordinates, collections, searches, and user interaction — and then carry those ideas into a completely new project.

By building real things, making natural mistakes, examining why they fail, and discovering the underlying rule instead of memorizing the correct code.

Because the goal is not to avoid every programming mistake. It is to become someone who can walk into a trap, understand it, get out, and recognize it the next time.