lua-users home
lua-l archive

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


It would break everything, but I'd remove the top-level function keyword entirely, with the side effects. 2 more keystrokes for `=` in free functions, plus 4 for `self` in methods.

It's really not so bad. It's more visible. You need to write ``x = function (self, ...)`` in some places no matter what. It would become more clear that function declarations in lua are just assignments. It's also less to parse, and one less thing for new users to trip on. I did attempt the nonsensical ``x:y = function (...)`` when I was first learning! When I write lua now, I prefer to write ``x.y = function (self, ...)`` for everything that uses a self, because I want to be very clear whether its a free function or a method (prefer free functions!). I don't know if it would warrant removing the `x:y(args)` call syntax, I'm okay with a shorthand if the behavior is consistent, and the ``self`` is just repeated text which was passed anonymously to begin with. Speaking of, the ``x:y{key: value, ...}`` call is a delicious and useful shorthand for named method args.

I'm also reasonably sure that you could convert any valid lua program using the top-level function keyword into a valid one with the other syntax. Correct me if I'm wrong on that, edge cases are always fun.

On Thu, Sep 6, 2018 at 12:35 PM Tom Sutcliffe <tomsci@me.com> wrote:
> 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