develooper Front page | perl.perl5.porters | Postings from March 2020

Re: Thoughts in the direction of a core try/catch syntax

Thread Previous | Thread Next
H.Merijn Brand
March 13, 2020 11:14
Re: Thoughts in the direction of a core try/catch syntax
Message ID:
On Fri, 13 Mar 2020 10:30:52 +0000, "Paul \"LeoNerd\" Evans"
<> wrote:

> However, my observation of the success of Switch::Plain and my
> thoughts on a dumb-match point me in the opposite direction now. In
> 99% of all realworld cases involving a typed dispatch, one entire
> dispatch block provides one *single* comparison operator - maybe
> string equality, numerical equality, class derivation, regexp pattern
> match (eq, ==, isa, =~). The neatness of dumb-match is that the
> programmer specifies which kind of match is being used in this
> instance at the point of the `switch`-like place, not the individual
> `case`s.

I have a few real-world switches, all use *just* 4 cases

  when (undef)
  when ("fixed-string")
  when (42)
  when (qr{^foo})

My longest production-case switch/given is 206 lines long, it has
• 33 when (qr{foo | bar})
• 19 when ("foo")

That script has 2600 lines of embedded documentation and about 800
lines of code and comments: this means that 25% of the script is taken
by the given/when block

H.Merijn Brand   Perl Monger
using perl5.00307 .. 5.31      porting perl5 on HP-UX, AIX, and Linux

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About