[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: suggestion: __typeof()
- From: "Dolan, Ryanne Thomas (UMR-Student)" <rtdmr6@...>
- Date: Tue, 17 Jan 2006 15:59:59 -0600
I still say there is no issue. Maybe I wasn't being clear:
T = {};
M = {};
M.__typeof = function () return "userdata", "MyType" end;
setmetatable (T, M);
--old code:
if type (T) == "userdata" then
print "Old code still works";
end;
--new code:
t, s = type (T)
if t == "userdata" and s == "MyType" then
print "new code can take advantage of extra info";
end;
See? The new behavior of type () should be as follows: If there is a __typeof metamethod, then call it and return the results. Otherwise, use default behavior (return "table", "userdata", etc). The metamethod can just return two values to avoid breaking older code that expects only "userdata" or "table".
Now, of course if I define a __typeof metamethod that only returns one value, then it can potentially break older code. But it should be up to the programmers whether to include backwards compatibility in their scripts. The language should not be held back just because an improvement might allow a poor programmer to break older, poorer code. Coming up with some patch is a way worse alternative.
-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br on behalf of Asko Kauppi
Sent: Tue 1/17/2006 2:45 PM
To: Lua list
Subject: Re: suggestion: __typeof()
Hmm.. the old code will break only _if_ the new type() is there _and_
some userdata implements the __typeof metamethod.
I think this makes the chances rather slim, also the calling code
would implicitly expect Lua never-ever to get any more types than it
now has, which is bad presumption anyhow.
-asko
Alex Queiroz kirjoitti 17.1.2006 kello 16.25:
> Hallo,
>
> On 17/01/06, Lisa Parratt <lisa@thecommune.org.uk> wrote:
>>
>> So because someone might cut their fingers off, we shouldn't use
>> knives?
>> Just because someone might burn themselves, we shouldn't cook food?
>>
>
> Please stop trying to be Lao-Tze.
>
>> Just because a facility has consequences that may be problematical
>> is no
>> reason to utterly dismiss the facility.
>>
>
> Luiz is talking about all the old code that would break with this
> new type function. Unfortunately people can't see the future yet, so
> as to avoid burning themselves.
>
> --
> -alex
> http://www.ventonegro.org/
<<winmail.dat>>