[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: (not) handling new programming idioms with grace
- From: Dirk Laurie <dirk.laurie@...>
- Date: Wed, 18 Jul 2018 18:03:11 +0200
2018-07-18 17:55 GMT+02:00 Roberto Ierusalimschy <firstname.lastname@example.org>:
>> On 18 July 2018 at 15:20, Roberto Ierusalimschy <email@example.com> 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.
At the Lua level, maybe
where 'level' behaves as in 'error'?