Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 06 Apr 2010 11:00:34 -0700
From:      Chuck Swiger <cswiger@mac.com>
To:        "Randal L. Schwartz" <merlyn@stonehenge.com>
Cc:        RW <rwmaillists@googlemail.com>, freebsd-questions@freebsd.org
Subject:   Re: perl qstn...
Message-ID:  <2EE33758-C39C-41DC-B6A8-B34CF6B3B25A@mac.com>
In-Reply-To: <86wrwkiunp.fsf@red.stonehenge.com>
References:  <4BB8108A.9080104@FreeBSD.org> <1270371713.5861.98.camel@tao.thought.org> <86aatjnsts.fsf@red.stonehenge.com> <861vevnsow.fsf@red.stonehenge.com> <j2ya14066a01004040945z39191770k2f025752317fb14a@mail.gmail.com> <20100404163353.GA15198@guilt.hydra> <20100404201442.b456044e.freebsd@edvax.de> <o2oa14066a01004041148zd4ef8167q32b04d58daec8f9f@mail.gmail.com> <4BB9A5ED.3040309@infracaninophile.co.uk> <20100405173632.739a0c42@gumby.homeunix.com> <20100406015544.GA21119@guilt.hydra> <20100406132049.641b9edf@gumby.homeunix.com> <86wrwkiunp.fsf@red.stonehenge.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi--

On Apr 6, 2010, at 6:21 AM, Randal L. Schwartz wrote:
>>>>>> "RW" == RW  <rwmaillists@googlemail.com> writes:
> RW> Imperative languages have a natural order of decision followed by
> RW> action, and code is most easily readable if the syntax doesn't try to
> RW> subvert that.  
> 
> And yet, there's an equally valid argument that the most important
> thing should stand out the most.  In that sense, in the Perl statement:
> 
>  warn "x = $x, y = $y, z = $z\n"
>    if $debug;
> 
> ... the most important part is that it's printing something to stderr,
> and what's being printed.  It's only minor that it's only when
> debugging, and luckily Perl lets us relegate that to the tail end of
> the statement.
> 
> Now, if you argue "oh, the most important thing there is 'if debug'",
> then fine, you'd write that as:
> 
>  if ($debug) { warn ... }
> 
> And I'd be fine with that.

Let's suppose you want to display one message if debugging is enabled, and a shorter message if it is not.  Adding an else clause to an if statement is a natural change and the result remains highly readable.  Can one even use this postfix test syntax with an else, or would you have to re-write the first version entirely?

As far as I am concerned, the first version resembles exception handling, ie:

  try:
     <something>
  except Error1:
     <handle error>

...and should be reserved for situations where the statement is expected to run normally.  If it is reasonable that the test might fail more often than in unusual circumstances, then I'd really prefer to put the test first.

> If you don't like all this freedom, there's always Python. :)


Yes, Perl lets you innovate a remarkable number of ways of solving the same problem using syntax that varies from clean and maintainable to constructs which even the original author won't understand without effort a few months later.  It seems to be uncommon for one to write unreadable Python code; I'm not sure additional freedom to write obfuscated code would be as beneficial as one may assume....

Regards,
-- 
-Chuck




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2EE33758-C39C-41DC-B6A8-B34CF6B3B25A>