[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: `depreciated` attribute for Lua?
- From: Lars Müller <appgurulars@...>
- Date: Tue, 12 Sep 2023 11:54:00 +0200
The main problem I see is that it is entirely inadequate.
Variable attributes are tied to variables, not to values. const
affects the variable, not the value inside it (which can be
mutated just fine). close closes whatever is in the variable.
Deprecations however should be tied to values, not to variables.
Functions are first-class, so what if I do mytable.reduce(t, add)?
At this point the variable becomes an argument of reduce (the
value is put on the stack when calling), and the deprecation info
tied to the variable would be lost.
Attributes only apply to local variables (everything else would
complicate tables, since environments are just tables and
implementing e.g. const for environmentals would require the
ability to mark table slots as immutable). This makes them pretty
much useless for libraries: Libraries typically either stuff their
functions in API tables (for which attributes can't be used)
either by directly assigning functions as myapi.myfunction or by
setting the environment to myapi.
That leaves us with deprecation warnings only if the variable (not
the value) is directly accessed - that is, only in the scope of
the local. This is hardly useful - just leave a few HACK/TODO
comments or directly grep for the usages and fix them instead. For
functions your library exposes, warn inside the function as bil
til said (which is also more flexible - often you just want to
deprecate some legacy signatures). For deprecated table fields
your library exposes, you can use __index or __newindex
metamethods to warn.
On 12.09.23 03:23, Frityet wrote:
My friend had an idea, much like const, a `depreciated` attribute
that warns when used
local add<depreciated> = function(a, b)
return a + b
end
add(1, 2) --warning
Thoughts?