[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Assignment Expressions in Lua
- From: "Jasper Klein" <jasper@...>
- Date: Thu, 25 Jul 2019 21:46:44 +0200
Op Tue, 23 Jul 2019 16:10:09 +0200 schreef Pedro Tammela
<pctammela@gmail.com>:
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/
Maybe I missed the momentum of the discussion but I would like to see
something similar in Lua.
It encourages to use RAII, and reduces the scope of the variable.
We already have in Lua some form of assignment expression in... for loops.
No one has been complaining about that.
Another example is C++17 that allows you to do something like:
if( auto foo = get_foo() ; foo.bar() == 42 )
{
foo.baz( 1337 );
}
-- Jasper