uqbar-project / wollok

Wollok Programming Language
GNU General Public License v3.0
60 stars 16 forks source link

Allow "return" statements in "then always" blocks ? (try) #423

Closed javierfernandes closed 8 years ago

npasserini commented 8 years ago

I am not sure but I might vote for not allowing them.

On Sun, Nov 15, 2015 at 9:02 PM, javierfernandes notifications@github.com wrote:

— Reply to this email directly or view it on GitHub https://github.com/uqbar-project/wollok/issues/423.

flbulgarelli commented 8 years ago

Why not?

Could you explain pros and cons?

javierfernandes commented 8 years ago

I think that the community tries to avoid having a return in a "finally" block http://stackoverflow.com/questions/48088/returning-from-a-finally-block-in-java (the link is broken :()

npasserini commented 8 years ago

Because the objective of a "finally" is to release resources, not to implement "domain logic". (Moreover, I think we have it there "just in case" for completitude, I am not sure about teaching it in elementary courses.)

Also we have to think that we can get there from different paths, for example:

try { ... return foo } then always { ... you already returned a value, does
it make sense to override it? }
try { ... } catch e { return bar } then always { ... again a value has been
returned }
try { ... throw exc } then always { ... an exception was thrown and not
cached, you shouldn't mess with return here, catch the exception instead }

I can not think of a good example in which the return in the finally block can not be more gracefully rewritten using try and catch. Can you?

On Mon, Nov 16, 2015 at 9:40 AM, javierfernandes notifications@github.com wrote:

I think that the community tries to avoid having a return in a "finally" block

http://stackoverflow.com/questions/48088/returning-from-a-finally-block-in-java (the link is broken :()

— Reply to this email directly or view it on GitHub https://github.com/uqbar-project/wollok/issues/423#issuecomment-157015637 .

npasserini commented 8 years ago

Given that there was no discussion after more than one month I think I can close it.

javierfernandes commented 8 years ago

Yeah, but the question now is if we must add an static check to forbid using return in "then always". I think that today it will let you

npasserini commented 8 years ago

Y would forbid it, I can't think of a good example. Can you?

On Tue, Dec 29, 2015 at 9:53 AM, javierfernandes notifications@github.com wrote:

Yeah, but the question now is if we must add an static check to forbid using return in "then always". I think that today it will let you

— Reply to this email directly or view it on GitHub https://github.com/uqbar-project/wollok/issues/423#issuecomment-167782935 .