(Sent to advocacy by request of Kurt.)

At 21.02 -0500 2000.05.24, Autarch wrote:
>On Wed, 24 May 2000, Dan Sugalski wrote:
>
>> * Things are only optional if it's painfully obvious what's going on
>> without them. Parenthesis, generally speaking, aren't optional. Neither are
>> meaningful comments.
>
>Hmm, both you and Tom mention this but one of the things I like most about
>Perl and the way parentheses can be used is that it lets you create syntax
>that is closer to natural language and less programmer-ish.  That said,
>whenever I do logical combos of and/or I use parens.  However, for things
>like each, defined, and so on I like to drop the parens.

It depends on the surrounding context.

  if (defined $foo && $bar) {  # potentially confusing

  if (length $foo > 6) { # potentially confusing

  if (defined $foo) { # not confusing

  close FOO;  # not confusing

When a function or operator is clearly by itself, I don't use parens.  When
there is possibility of confusion, I use them.

By "possibility" I mean "using a minimum of logic, a novice Perl programmer
still might get confused."  If someone is confused by either of those last
two examples, well, I don't want that person working on my code.  :-)

I personally don't see how someone can say "things are optional if it's
painfully obvious what's going on without them" and "parentheses, generally
speaking, aren't optional."  Generally speaking, it is painfully obvious
what is going on with the last two.  Here are some more that I think are
painfully obvious:

  open FILE, "< $file" or die "Can't open $file: $!";

  mkpath $path, 0, 0755 or die "Can't mkpath $path: $!";

  my $foo = 1;

  if ($foo eq 'bar' && $baz eq 'buz') {

I use parens a lot.  I skip parens a lot.  Am I really off base thinking
the above cases are painfully obvious without parens?

-- 
Chris Nandor       |     [EMAIL PROTECTED]      |     http://pudge.net/
Andover.Net        | [EMAIL PROTECTED] | http://slashcode.com/

Reply via email to