[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: (not) handling new programming idioms with grace
- From: Roberto Ierusalimschy <roberto@...>
- Date: Wed, 18 Jul 2018 12:55:04 -0300
> On 18 July 2018 at 15:20, Roberto Ierusalimschy <firstname.lastname@example.org> wrote:
> > I did not get your point here. Why a user that would forget to properly
> > qualify its 'local' would not forget to use 'with'? What are the
> > differences between 'local scoped' vs 'with' except the syntax?
> it's precisely the syntax. a 'with' block is always an extra block,
> even if it covers the whole loop or function block (it usually
> doesn't). it's very visible, and so hard to miss. if a novice
> programmer sees the `with open('fname') as file: xxxx` and likes it,
> they will probably use it very intentionally.
It is not by chance that Lua avoids too many syntactical constructs.
They are hard to be represented in the C API.
A good use I see for "local scoped" is in C functions, which often have
a hard time to properly free resources. With something like "local scoped",
it would be enough one single function to mark a stack position as
a scoped variable, to be finalized when the function exits.