Code Room
Vibe codingMedium
Question
An AI agent wrote save/load for an RPG in C# using BinaryFormatter-style field-order serialization. It works in testing. After you ship a patch that adds one field to the player struct, every player's existing save loads with corrupted inventories and wrong stats. Review the serializer and explain the save-game bug.
void Save(BinaryWriter w, PlayerState p) { w.Write(p.level); w.Write(p.health); foreach (var item in p.inventory) w.Write(item.id); w.Write(p.gold);}PlayerState Load(BinaryReader r) { var p = new PlayerState(); p.level = r.ReadInt32(); p.health = r.ReadInt32(); // read inventory until we hit gold... how many items? p.inventory = ReadAllRemainingAsItems(r); p.gold = r.ReadInt32(); // BUG: nothing left, or reads an item id as gold return p;}What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.