Good Code
The good version uses named fields, so callers can read the table as a record and access values without remembering index positions.
Lesson 01
Keep table shape clear when a value behaves like a record, array, or map.
local function build_review_summary(title, score)
-- Named fields make this table read like a stable record.
return {
title = title,
score = score,
approved = score >= 4,
}
endlocal function build_review_summary(title, score)
-- Positional fields hide what each slot means to the caller.
return { title, score, score >= 4 }
endThe good version uses named fields, so callers can read the table as a record and access values without remembering index positions.
The bad version mixes unrelated values into positional slots. A caller has to know that index 3 means approval state, which is easy to break during later edits.