lua-users home
lua-l archive

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


> On 31 Jul 2018, at 11:16 pm, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
> 
> Are there features in Lua that could be removed to create a simpler language?

Interesting question.

> On 1 Aug 2018, at 8:03 am, Axel Kittenberger <axkibe@gmail.com> wrote:
> 
> dibyendu> Are there features in Lua that could be removed to create a simpler language?
> 
> - the .. operator and with it implicit string/number coercions. 
> - goto, the only sensible applications IMO can be replaced with better: continue and a more sophisticated try/except/throw scheme than pcall.
> 
> As a rule of thumb I'd say, if it's a feature that's not found in most other programming languages in similar areas and it's controversial, it was probably not that good of an idea. However, if it's a feature that distinguishes Lua from other programming languages and there is a wider consensus about it, it probably was one of the better ideas (for example the : operator vs. JS 'this' shenanigans, or metatables in general etc.).

I think that's a good summary.

I haven't personally found a use for gotos in Lua, but I'm sure they are useful when translating code from another language which has them (or in machine-generated code), so I don't really object to them as they never get in my way. I just don't use them.

The only thing that I'd really get rid of is the implicit string/number conversions. Those you *do* unavoidably hit just by using numbers and strings and occasionally not realising there's a wrong type somewhere. I'd much prefer less magic and more "you've done something wrong here" errors. Javascript's handling of type coercions is insane, C++ is pretty close, basically implicit type conversions are almost always a slippery slope of unpleasantness. lua_tolstring being able to mutate the underlying value and mess up lua_next (amongst other things) is one of those gotchas that just shouldn't exist, and is (imo) one of the few genuine missteps in the Lua C API. KISS is the only way to go here which keeps your sanity intact.

I think I've pretty much used every other aspect of Lua in a significant way, by which I mean there's a real-world project relying on it. coroutines, debug, utf8, userdata, most metamethods, bitwise operators, ability to build for severely resource-constrained platforms with a compiler that doesn't even support floating point, I've used them all. Maybe weak tables? I don't think I've yet relied on them although I've come close a few times, so I don't think I'd be happy if they weren't an option. string.reverse I admit I've never ever used, although the 'cost' to the language of having it is so minimal I don't really care, and it's interesting to see that some people have found a use for it. Lua's string pattern matching you can prise from my cold, dead hands given how much simpler and smaller it is to regex (while being still pretty powerful) and how it's actually built in (yes std C++, I'm looking at you).

Lua is pretty much the definition of everything I really need in a language, and nothing that I don't. Which is one of the reasons I like it :-)

Cheers,

Tom