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.
Text, time and money: classic data traps
card 3 of 6
Three tells and their safe types
builds on: Why agents fill gaps with plausible guesses
- **Text**: `len`, `.length` or slicing on user text. Go and Rust count UTF-8 bytes (Rust panics, i.e. crashes, if a slice cuts a character). JS and Java count UTF-16 code units; Python counts code points. None counts graphemes. Case-insensitive matching: Python `casefold()`, Go `strings.EqualFold`, Java `toLowerCase(Locale.ROOT)`.
- **Time**: naive `datetime.now()`, `LocalDateTime`, or `+ 86400` seconds as 'a day'. Use UTC instants plus a named zone (`zoneinfo`, `ZonedDateTime`, `time.LoadLocation`). Add days with calendar math (`plusDays`, Go `AddDate`).
- **Money**: `float`, `double`, JS `number`. Use `Decimal` or `BigDecimal` built from strings, or integer cents (common in Go, Rust, JS).
Terms on this card
- UTF-8
- A text encoding that stores each character in 1 to 4 bytes. ASCII takes 1 byte, 'é' takes 2, most emoji take 4. Used by Go and Rust strings.
- UTF-16 code units
- The 16-bit pieces that JS and Java strings are made of. Most emoji need two of them, called a surrogate pair.
- code points
- Numbered Unicode characters. 'é' can be one code point, or 'e' plus a combining accent, which is two.
- graphemes
- What a reader sees as one character. It can be several code points, such as a flag or an emoji with a skin tone.
- case-insensitive matching
- Comparing text while ignoring upper and lower case. Done naively, it fails for letters like German 'ß' or Turkish 'I'.
Lesson goal: Spot agent code that is wrong for real-world data: string length, slicing or case-folding that breaks on non-ASCII text, naive datetimes and DST or time-zone shifts, and floating-point arithmetic for money. Name the safe type or library in each language (for example Decimal or BigDecimal, integer cents, zone-aware datetimes). ·
the whole lesson