[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: question on <close>
- From: pocomane <pocomane_7a@...>
- Date: Wed, 20 May 2020 17:20:08 +0200
Yes, you can write all what you want with label and goto, you neither
need 'for' and 'while' loops. The hypothesis is that all these
constructs make it simple to read/write/maintain the code.
For the specific case of <close>, the first advantages I can think of are:
1) You put the finalization code near the initialization one
2) Library can return structured objects that know how to be closed
(i.e. a library have not to specify "Close the object with the X
method")
3) It play very well with other constructs, like the new 'for' semantic [1]
[1] https://marc.info/?l=lua-l&m=158760544231443&w=2
On Wed, May 20, 2020 at 4:54 PM Andrea <andrea.l.vitali@gmail.com> wrote:
>
> I now understand the rationale for <close> but I would like to ask a hypothetical question.
>
> <close> causes something to happen when a variable goes out of scope, which happens when a block terminates - for local variables in functions, this happens when a function return
>
> so my question is:
>
> could one get away by substituting all returns with a goto label, and after the label put the code necessary to close the variable?
>
> from my point of view this could also be done in every block: am I right?
>
> I guess this has already been discussed and there is some additional advantage in having a <close> attribute
>
> but I am curious - thank you very much for your patience
>
> Andrea
>
>
> --
> Andrea Vitali
>
>
>
>
>
>