Chapter 14. Structuring Programs in the AI Era: Objects, Data and Async
- Approved by
- Panaversity ·
The point
If the agent writes all the code, why learn how it is put together? Because almost every program an agent writes for you, and the code companies publish for their services, is split into many files, each with one job. Knowing that shape lets you find your way, and find where data comes in.
What protects a program when its data changes? A check at its edges, the lines where a file or another program's answer comes in. These are places in the code, not Chapter 13's edge cases. There, a schema, a written description of valid data, checks every record on every run. It stops the run with a list of every bad row. Marcus's script, below, had an edge with no check.
What is left for me to decide? What valid data looks like, what the program does when data is bad, and the cases each test checks, with their answers. The agent writes the code from your decisions, and you read the lines that carry them.
After this chapter you can find the edges of a program an agent wrote, and say what each edge refuses. You can also find your way around a project an agent split into files, and write down which values your data may hold. You can call another program over the web, and read code that waits for several slow answers at once.
Why it matters
Marcus runs accounts payable for a restaurant-supply distributor in Fort Wayne, Indiana. Every Thursday a script downloads the week's invoices from a vendor portal and builds the payment file for the bank. An agent wrote the script in an afternoon, and it ran without trouble for months.
One week the portal changed one field. The amount, which used to arrive as a whole number of cents, such as 482500, now arrived as text with a currency sign, such as "$4,825.00". That Thursday the script ran as it always did, and nobody was reading it. His company checks every delivery at its loading dock, but his script checked nothing that came in. It converted each amount with a function that returns "not a number" for text it cannot read. A later line turned "not a number" into zero. The script loaded all 2,000 invoices, reported success, and wrote a payment file in which every amount was $0.00. The bank rejected nothing, because every line of the file had the right format. Forty vendors went unpaid, and Marcus spent the next week calling them.
Not one line of the script had changed since the afternoon it was written. Only its input had. Three lines at the edge of the program, saying what a valid amount looks like, would have read that input on that Thursday. They would have stopped the run before any payment file was written. The report would have started with "line 2, amount: expected a whole number of cents, got text". This chapter teaches you to look for that edge in every program an agent writes.
Sources
- Owner
- Panaversity