lua-users home
lua-l archive

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


On Wed, Jul 18, 2018 at 12:55:04PM -0300, Roberto Ierusalimschy wrote:
> > On 18 July 2018 at 15:20, Roberto Ierusalimschy <roberto@inf.puc-rio.br> 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.
> 
> -- Roberto

That's intriguing.

I wish people (myself included) would keep in mind the symmetry that Lua
tries to maintain between the language and the C API. Aside from making the
C API incomparably superior to other language implementations, the
constraint keeps Lua honest and careful. If a feature can be elegantly
expressed and implemented for *both* the language and the C API, that's
strong evidence it's a quality choice. If it can't be, it suggests to keep
searching.

The filter may not have a great false negative rate, but the false positive
rate is where it really produce dividends. Many proposals on the list could
be and should be easily dismissed amicably by applying this filter without
us having to be reminded.