develooper Front page | perl.perl5.porters | Postings from October 2021

Re: Pre-RFC: try/catch/finally and generic finally blocks

Thread Previous | Thread Next
From:
Oodler 577 via perl5-porters
Date:
October 19, 2021 23:44
Subject:
Re: Pre-RFC: try/catch/finally and generic finally blocks
Message ID:
YW9YU2X49kW5LXOH@odin.sdf-eu.org
* hv@crypt.org <hv@crypt.org> [2021-10-19 21:49:47 +0100]:

> "Paul \"LeoNerd\" Evans" <leonerd@leonerd.org.uk> wrote:
> [...]
> :  try {
> :    ## 100 lines here
> :  }
> :  finally {
> :    say "Oh and just do this before you go"
> :  }
> [...]
> :  {
> :    ## 100 lines here
> :  }
> :  finally {
> :    say "Oh and just do this before you go"
> :  }

Replying to Hugo's comment only to honor it; but in the case of
the bare block this seems like a NOOP unless "finally" implies a
"wait" or waitpid for thing, but I don't know what things that
could be other than a child process spawned by either C<fork> or
an explict background shell command via C<system> or C<``> or
C<qx//>, etc.

LABEL:
{
 #  do stuff
 # spawn a child proc
}
finally {
 # do more stuff but what's
 # the state of child process?
}

1. when does `finally` get executed, does it wait for child pid? 
2. does LABEL: work as expected if one does, `next LABEL;`?

Cheers
Brett

> :
> :There was no `try` at the top, meaning the reader didn't get lulled
> :into a false sense of security by thinking there's exception-catching
> :going on here when there isn't. It's just a bare block, doing what bare
> :blocks do.
> 
> On the other hand, there is also the possibility now that you end up
> with:
> 
> {
>   # couple of lines here
> }
> # 100 lines of comments here
> finally { ... }
> 
> I think it's unwise to try to mitigate every case of "100 lines here",
> it seems like a short road to madness. But if you want to avoid it in
> this case, I think you'd need yet another keyword. I'm not convinced
> that the language is improved by tacking an optional continuation onto
> bare blocks.
> 
> Either way, I do think we should be encouraging Perl developers to write
> their code so as to minimize confusion, eg by factoring away "100 lines
> here".
> 
> Hugo

-- 
--
oodler@cpan.org
oodler577@sdf-eu.org
SDF-EU Public Access UNIX System - http://sdfeu.org
irc.perl.org #openmp #pdl #native

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About