lua-users home
lua-l archive

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


On Tue, Jul 23, 2019 at 9:10 AM Pedro Tammela <pctammela@gmail.com> wrote:
In Python 3.8 there will be a new feature introducing Assignment Expressions[1]. One of the reasons for such feature is to improve code readability, among other things.

Would assignment expressions improve Lua code readability?

[1] https://www.python.org/dev/peps/pep-0572/

Python programmers want assignment expressions because Python's comprehension syntax is so heavily used. They've been asking for assignment expressions literally for decades and it's only now that Python's programming style has evolved to the point where it's hard to express some things in any other efficient way that Guido has given in to the pressure.

But Python's programming style has only evolved that way BECAUSE of Python's comprehension syntax. Lua does not have anything like it. Python's comprehension syntax involves evaluating an _expression_ multiple times with different values, and nothing in Lua does this -- all expressions are evaluated immediately. If you want that behavior, you use a function, full stop.

Lua intentionally does not have assignment expressions; this was debated (again) fairly recently. Given that even PEP-572 includes explicit admonishments to avoid using assignment expressions except when absolutely necessary, and given that Python's rationale for including them doesn't apply to Lua, I see no reason why Lua's stance on the matter should change.

/s/ Adam