lua-users home
lua-l archive

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


On Apr 21, 2017 4:17 AM, "Oliver Kroth" <oliver.kroth@nec-i.de> wrote:

Do you have anything else that comes to your mind? I would also greatly appreciate input regarding other languages that implement these things above and how it's done there. I'm quite fluent in Java, C#, C, _javascript_ and knowledgeable in C++ and PHP. While reflection works in these languages (somehow), it's often requires very arcane knowledge to do similar things as mentioned 1-3.

What I like very much at Lua, and use a lot:

- you can use anything as index in a table, including other tables, functions, coroutines, and userdata, like sockets.
This saves a lot of CPU time when managing these resources

- multiple vale assignment, and especiall the fact that functions may return multiple values like
  a,b = b,a
or
  angle, radius = toPolar( x,y )

- closures are great for, e.g. scheduling actions, as parameter for pattern substitution, iterators, etc.
once I got the concept, I don't want to miss them again.

- string.gsub() is one of the best find and replace implementations I came across  in my not too short programming history.
Not even that one can use a function (more precisely a closure) as parameter for the substitution, a table is fun enough.
It is not often that a UTF-8 to something else conversion is a one-liner:
  win1252 = utf8:gsub(  '[\xc0-\xef][\x80-\xbf]+', utf8ToWin1252 )
(utf8ToWin1252 is a table with the UTF8 encoding as keys and the win-1252 encoding as values)

--
Oliver

Agreed with all this. What I love about Lua is not just that it provides powerful tools such as closures, coroutines, first-class functions, multiple assignment, pattern matching, and hash tables​ all built in, but that it does so while remaining very easy to understand and very lightweight.

In Python I often find myself having to double check if I've created a closure correctly; multiple assignment sometimes trips me up when I want to return a list, not everything can be used as a dict key, and I'm not sure about coroutines. It has all the same features, but Lua just makes them all so elegant.