Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Lua is not weakly typed (at least not in the sense of Javascript and PHP where "3"+4 is either 7 or 34, can't remember which.

In JS, "3" + 4 is "34", in PHP, it's 7. PHP separates concatenation and addition, unlike JS.

Anyway, huh? Lua has automatic type conversion. That's usually considered weak typing.



Its just for "+" and ".." though. For other things, such as equality and table indexing numbers and strings are not interchangeable.


In Lua "3"+4 is an error. Concatenation is a different operator than add, specifically to avoid confusing coersions.


Try it:

    Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
    > ="3" + 4
    7


Ah. Well at least there isn't a confusion between add and concat

"3"+4 is 7 4.."3" is "43"

"3hello"+4 is an error


Stand corrected with the example. I forgot about the lua auto type conversion - but that, on its own does not make weak typing - Python, C and Java do that between floats and ints, would you consider them weak typed?

I'm not familiar with a rigorous definition of weak typing - but my experience is that weak typing is usually reserved for languages like TCL, Snobol, and even Perl where there's no "type" of values to speak of - everything is equivalent and decoded according to context.


That's the problem with those terms, both 'weak' and 'strong' typing are purely subjective.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: