[Gambas-user] Finally/Catch and Return: How is that meant to be used?

Gianluigi gradobag at gradobag.it
Thu Sep 14 22:28:33 CEST 2023


Il 14/09/23 19:22, Martin Fischer ha scritto:
>> Il 14/09/23 16:48, Martin Fischer ha scritto:
>>>>
>>>> I think (but I'm not sure) that this answer your question:
>>>>
>>>> http://gambaswiki.org/wiki/lang/finally?nl
>>>>
>>>> Regards
>>>>
>>>> Gianluigi
>>>>
>>>
>>> Gianluigi,
>>>
>>> thanks for the reference, but I'm aware of that already.
>>> My problem comes from this harmless looking paragraph in the document
>>> you referenced:
>>>
>>>     This does not completely Ensure that code is run no matter what.
>>>     If RETURN is used to exit a function before Finally then the
>>>     Finally part will only run if an error is raised.
>>>
>>> This is a substantial deviation from "Finally"-semantics in other
>>> languages. This is why I'm surprised...
>>>
>>> Regards,
>>> Martin
>>>
>>>
>>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>>
>>
>> Hi Martin,
>>
>> Many thanks you for the explanations, but it seems to me that if all
>> languages have to follow dogmas why there is so many and all different?
>>
>> Regards
>>
>> Gianluigi
>>
>>
>> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
>
> Hi Gianluigi,
>
> for me, it's not about dogma. I'm fine with different languages solving
> problems differently. A C program uses different patterns than a C++
> program or a Python or a Java program.
>
> My point is that during the evolution of languages some patterns appear
> over and over again. Because there is a need to solve very similar
> problems in these languages!
>
> Let's take for example the pattern "function". This thing takes
> parameters from the caller, does something and returns something to the
> caller back. This solves the problem of abstracting functionality that
> has to be used at multiple places with only slight variations (the
> parameters). And so on...
>
> This is such a common problem in programming languages that most of them
> have "functions".
>
> Now, let's move to the Finally-pattern. This stands for an abstraction
> that allows you to execute a block of code as final operation of a
> function, no matter how this function was left (normal return or
> exception). As such it allows you to clean up resources allocated during
> the function very easily and reliably. Again, this is such a common
> problem that many languages have a means to implement this pattern.
>
> You might be aware of the old VisualBasic way of solving this problem.
> Yes, you could do it, but it was effort and error-prone. Maybe this is
> the reason why gambas decided to offer a Finally pattern.
>
> My surprise was just that gambas implements this Finally-abstraction in
> a leaky way. Means: the usual "Finally guaranties that the finally-block
> is executed no matter how you leave the function" does not hold. Instead
> a weaker guarantee is implemented that does not solve the complete
> problem that is normally solved by Finally.
>
> But: I do not complain. I just want to understand how gambas works.
>
> Regards,
> Martin 


Dear Martin,

it is clear that you are a good programmer and you know what you are 
talking about.
You were very kind to answer me and also very clear in your explanations.
You reminded me of someone I respect and it won't be long before he 
explains to me how to use Gambas :-)

It's night here so I wish you a goodnight
Regards

Gianluigi



More information about the User mailing list