[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] MacPerl beautifier? (written preferably in Perl?)



charles@jolt.mpx.com.au,	mac-perl@iis.ee.ethz.ch
Subj:	[MacPerl] MacPerl beautifier? (written preferably in Perl?)

Charles Cave wrote a message received 19-MAY-1997 

>I am looking for a perl program that takes a perl program
>and formats it to maximise clarity and readability. C programmers
>will be familiar with "cb" (C beautifier), and I was thinking it
>would be nice to have a program to help format a MacPerl program.
>
>My objective of such a utility is to ident the code so
>the opening and closing braces are paired up nicely.
>For example:
>
>Before:
>
>1 while (<>) {
>2 if (/Fred/)  {
>3 $fred = 'Y';
>4 } elsif (/Frog/) {
>5 $frog = 'Y';
>6 }
>7 }
>
>After:
>
>1 while (<>) {
>2   if (/Fred/)  {
>3     $fred = 'Y';
>4   } elsif (/Frog/) {
>5     $frog = 'Y';
>6   }
>7}
>
>Correctly formatted code is much easier to understand!
>
>The programming environment I use at the office (Unidata/UniBasic)
>has a formatting option to draw vertical lines to show the structure
>of If/then/else statements and loop/while/repeat options...useful
>for printing but not compiling.  Example:
>
>1 while (<>) {
>2 |  if (/Fred/)  {
>3 |  | $fred = 'Y';
>4 |  } elsif (/Frog/) {
>5 |  |  $frog = 'Y';
>6 |  }
>7 }
>
>I've already started coding such a program, but I'm sure it has
>been done already.
>
>Charles

Sounds great Charles.  I cannot determine whether it is an email transmission 
problem or not but in the sample beatified code you sent:

1 while (<>) {
2   if (/Fred/)  {
3     $fred = 'Y';
4   } elsif (/Frog/) {
5     $frog = 'Y';
6   }
7}

You seem to be indenting by 1 (the while on line #1), 2 (the $fred and $frog on 
lines 3 and 5), or 3 (lines 2,4,6), spaces.  I am curious why you 
chose not to follow the perlstyle.pod page that states:

 Regarding aesthetics of code lay out, about the only thing Larry 
 cares strongly about is that the closing curly brace of a multi-line 
 BLOCK should line up with the keyword that started the construct. 
 Beyond that, he has other preferences that aren't so strong: 

      o 4-column indent. 

      o Opening curly on same line as keyword, if possible, otherwise line up.

True these are only preferences - but why not follow them?

Peter Prymmer


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch