lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Jul 21, 2015 at 1:14 PM, William Ahern
<william@25thandclement.com> wrote:
> Many people might argue that automagic coercion like this hides more bugs
> than it fixes. I'm not once of those people, but it's a reasonable argument.

Actually, I may be shifting to that position.  Why?  I have realized
that choice of either %s or %.0f may be an adequate alternative for
%d.

> Are you also suggesting that the following should work?
>
>         print(2.7 >> 1)

No, I do not believe I have ever suggested that.  I'd prefer an error.

My suggestion was limited to string.format.

> There's significant tension in Lua regarding strict typing versus automatic
> coercions. IIRC, over the years there have been suggestions to make code
> like this fail:

>         string.format("%d", "2")

Failure would be fine.

>         string.format("%s", 2)

Failure would be inconvenient, IMO.  Unless there is some other easy
way that I am unaware of to have 2.0 format to '2' and 2.7 format to
'2.7' ?

> IMO, permitting 2.0 to coerce to 2, but not 2.7, seems like a very sensible
> approach. And sticking to this rule also seems very sensible because it's
> principled--it emphasizes value preservation, without the burdens of
> worrying about context or strict typing. If you start having to worry about
> context (whether it should coerced or truncated in one construct but not
> another), strict typing might seem like the simpler approach overall.

Yes, I am now mostly inclined to agree.

-Parke