Good Code
The good version builds and returns a module table. A caller using require can see the exported surface and keep names scoped.
Lesson 03
Return an explicit module table so require calls expose a stable API instead of hidden globals.
local ReviewRules = {}
function ReviewRules.is_approved(review)
-- The exported function is visible on the returned module table.
return review.score ~= nil and review.score >= 4
end
return ReviewRulesfunction is_approved(review)
-- Global function names can collide across unrelated modules.
return review.score >= 4
endThe good version builds and returns a module table. A caller using require can see the exported surface and keep names scoped.
The bad version writes a global function during load. Another file can replace it, and tests can pass or fail depending on import order.