Replies: 2 comments
-
Hi! Glad you're enjoying Teal! I don't think there is a consensus. We do need forward declarations when there are circular dependencies. This is a byproduct of the language implementation's simplicity, which is one of its tenets. Lua itself needs forward declarations with circular dependencies on local functions, so it's not that far off unexpected. But I didn't want to enforce them in the language "for consistency" because I thought people would be annoyed by needless duplication (especially for people coming from dynamic languages, every additional annotation you force on them feels like an extra burden). So I would say it's fine to do it, and I don't think it feels "off" either (I think it's fine as at-a-glance documentation), but not necessary. |
Beta Was this translation helpful? Give feedback.
-
I do like that for my scripts: local record Plant
color: string
end
-- optional, see [1]
local Plant_mt: metatable<Plant> = { __index = Plant }
function Plant.new(color: string): Plant
return setmetatable({
color = color,
}, Plant_mt) -- [1]: could be just { __index = Plant }, thus no Plant_mt
end
function Plant:grow()
-- ...
end
return Plant |
Beta Was this translation helpful? Give feedback.
-
I've been kicking the tires on Teal for a few weeks now, and it's great. One thing I'm not sure of is whether it's idiomatic to define all the methods of a record in the record definition, or if you only do that when you need forward declarations?
Do you do this:
Or this:
Beta Was this translation helpful? Give feedback.
All reactions