[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: how to prevent bugs without static type checking?
- From: Coda Highland <chighland@...>
- Date: Mon, 22 Oct 2012 21:11:24 -0700
On Mon, Oct 22, 2012 at 9:07 PM, 乙振斐 <yizhenfei@gmail.com> wrote:
> Without static type checking, we may send wrong parameters to a function and
> we cannot find this mistake until the program crashes in run time.
> But if it is a huge program, we are not able to cover 100% codes in test, in
> this situation ,how can we prevent this problem?(say, pass wrong type
> parameters to a function)
>
> Sorry, I am a new comer with Lua, and it is the first time for me to learn a
> dynamic language, forgive me if this problem is ridiculous. But it really
> bothered me for a long time.
>
> Regards,
> Zhenfei Yi.
It's a tradeoff. The downside is that you don't have a "compile time"
at which to find type errors. The upside is that you can have "duck
typing", which means that an object only has to expose a certain
common API in order to be an acceptable parameter rather than having
to deal with some strict, static polymorphism.
That said, there are static analysis tools for Lua that do allow you
to annotate functions with information so you can get the security
where you need it.
/s/ Adam