On Fri, 22 Feb 2002, Michel J Lambert wrote:
> Instead, might I suggest BraceBeGone, a module I whipped up last night?
> 
> use BraceBeGone;
> if (...)
>   my @item_parts = split(/\n/, $item);
>   printf ORDER ("\n%4d   %-50s   %3.2f      %3.2f\n",
>   $quantity, $item_parts[0], $price, $ext);
> else
>   printf ORDER ("\n%4d   %-50s   %3.2f     %3.2f\n",
>   $quantity, $item, $price, $ext);

Cool.  However, it occurs to me that, since the fundamental problem in
the original example is a disagreement between the indentation and the
braces, which your module solves by eliminating the braces, wouldn't it
be even easier (and perhaps more perlish) to get rid of the indentation
instead?

  if (...) {
  my @item_parts = split(/\n/, $item);
  printf ORDER ("\n%4d   %-50s   %3.2f      %3.2f\n",
  $quantity, $item_parts[0], $price, $ext);
  } else {
  printf ORDER ("\n%4d   %-50s   %3.2f     %3.2f\n",
  $quantity, $item, $price, $ext);
  }

There.  Now it's obvious where the last brace belongs.  Or perhaps...

  if (...) { my @item_parts = split(/\n/, $item); printf ORDER ("\n%4d   %-50s   %3.2f 
     %3.2f\n", $quantity, $item_parts[0], $price,$ext); } else { printf ORDER ("\n%4d  
 %-50s   %3.2f     %3.2f\n", $quantity, $item, $price, $ext); }

Ah, that helped.  Who needs those pesky linefeeds anyway?

Seriously, the problem _is_ an internal inconsistency in the indentation
style employed -- the C<else> block has its closing brace on a separate
line, while the closing paren in the C<printf> is at the end of the
line.  Either of:

  else {
      printf ORDER (
         "\n%4d   %-50s   %3.2f     %3.2f\n",
         $quantity, $item, $price, $ext
      );
  }

or

  else
      { printf ORDER
          ( "\n%4d   %-50s   %3.2f     %3.2f\n",
            $quantity, $item, $price, $ext ); }

wouldn't have that problem.

(It occurs to me that getting used to the latter style and employing it
consistently in your programs could be an excellent way to guarantee job
security, while keeping the code readable for yourself.  Assuming, of
course, that the next guy after your job won't be a lisp programmer.)

-- 
Ilmari Karonen, "virtuaalisihteeri", Luonto-Liitto

Reply via email to