[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Is string always same as number? (the consistency of lua)
- From: Dirk Laurie <dpl@...>
- Date: Fri, 11 Feb 2011 19:03:50 +0200
On Fri, Feb 11, 2011 at 05:51:58PM +0200, Greg Falcon wrote:
> On Fri, Feb 11, 2011 at 8:23 AM, Dirk Laurie <dpl@sun.ac.za> wrote:
> > I ask you to grant that:
> > 1. People who do not use the feature are not in any way affected
> > by whether it is available or not.
>
> That's only true if their code has no bugs. If someone accidentally
> tries to add two strings together (maybe by using + where they mean
> ..), there's a chance it does an unexpected thing at runtime, rather
> than just raising an error.
>
On the other hand, if the use of 'tonumber' is compulsory, some
errors give less informative messages. Example: in the following
code, y is supposed to be a string that can be coerced to a number.
Some bug has caused y to be invalid.
If I rely on implicit conversion, I get:
> z=x+y
stdin:1: attempt to perform arithmetic on global 'y' (a string value)
If I avoid implicit conversion, whether because I abhor it or because
the thought police have taken it away from me:
> z=x+tonumber(y)
stdin:1: attempt to perform arithmetic on a nil value
I don't know whether x or y is causing the error, and if it is y,
I don't know its type.
Dirk
- References:
- Re: Is string always same as number? (the consistency of lua), Axel Kittenberger
- Re: Is string always same as number? (the consistency of lua), Philippe Lhoste
- Re: Is string always same as number? (the consistency of lua), Xavier Wang
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Miles Bader
- Re: Is string always same as number? (the consistency of lua), Miles Bader
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Xavier Wang
- Re: Is string always same as number? (the consistency of lua), Dirk Laurie
- Re: Is string always same as number? (the consistency of lua), Greg Falcon