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
From:
H.Merijn Brand
Date:
March 13, 2020 11:14
Subject:
Re: Thoughts in the direction of a core try/catch syntax
Message ID:
20200313121355.2739c33a@pc09.procura.nl
On Fri, 13 Mar 2020 10:30:52 +0000, "Paul \"LeoNerd\" Evans"
<leonerd@leonerd.org.uk> 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  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.31      porting perl5 on HP-UX, AIX, and Linux
https://useplaintext.email  https://tux.nl  http://www.test-smoke.org
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

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