Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Leaked resources: files, connections, goroutines
card 3 of 6
Tells: a release not tied to scope
builds on: Error handling idioms across languages
- **Python:** `open`, `connect` or `acquire()` outside a `with` block, or a manual `close()` placed after other calls.
- **Java:** connections, statements or streams not declared in try-with-resources; `unlock()` not inside a `finally`.
- **Go:** no `defer x.Close()` right after the error check; `defer` inside a loop; `resp.Body` never closed; `cancel` assigned to `_`; a goroutine that sends on a channel nobody will read.
For each one, ask: what releases this on the error path?
Terms on this card
- goroutine
- A lightweight concurrent function in Go, started with `go f()`. It lives until its function returns; a goroutine blocked forever is never freed.
- resp.Body
- The body of a Go HTTP response. It holds the underlying connection until you call `Close()` on it.
- defer
- A Go statement that schedules a call to run when the surrounding function returns, not when the current loop iteration or block ends.
- try-with-resources
- Java's `try (var x = ...) { }` form. It calls `close()` on each declared resource when the block exits, normally or by exception.
- finally
- A block after `try` that always runs, whether the try block returned normally or threw an exception. It is used for cleanup.
Lesson goal: Spot files, connections and locks opened without `with`, try-with-resources or `defer`, as well as `defer` inside loops, goroutines blocked forever and contexts never cancelled. Explain why these pass tests but exhaust resources in production. ·
the whole lesson