lua-users home
lua-l archive

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


I think this thread is running in a loop. I don't think it will change anyone's mind but let me give my point of view on this.

I was happy that to-be-closed variables ended up in Lua 5.4, even though I don't really like their interface (but I do not have a much better idea either). I think they should not be abused, and I do not particularly like <const>.

But there was one thing in particular that was really annoying to do before Lua 5.4, and that was properly managing cursor-like interfaces. By that I mean a variable used to iterate a collection that you must close afterwards. This is frequent when you use low-level databases, for instance.

In practice the way I use to-be-closed variables is often through the fourth variable of the generic for loop, so I don't even write <close> in my code.

In other words, I think to-be-closed variables is a very good addition to the language. Yes, you can shoot yourself in the foot if you try to do complicated things with them without a perfect understanding of how they work. The obvious solution is not to do that.

-- 
Pierre Chapuis