On Thu, Feb 21, 2002 at 11:31:16PM -0500, Keith C. Ivey wrote:
> Rick Klement <[EMAIL PROTECTED]> wrote:
> > Vicki Brown wrote:
>
> > > 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);
> > >
> > > --- End Forward ---
> >
> > Begin religious indenting style rant:
> >
> > Nawww, this is not the place for that :)
> >
> > I'll just let one's choice of indenting style be it's own punishment :)
>
> I don't like cuddled elses myself, but I'm not familiar with
> any indenting style that wouldn't have the same problem.
> What did you have in mind?
Having given the matter some thought, may I suggest the following style
which, if it were universally followed could all but eliminate this
class of error?
if (...)
#
{
#
# This is the start of the conditional block.
# Lines before this one are not executed as part of the conditional block.
#
my @item_parts = split(/\n/, $item);
printf ORDER ("\n%4d %-50s %3.2f %3.2f\n",
$quantity, $item_parts[0], $price, $ext);
#
# This is the end of the conditional block.
# Lines after this one are not executed as part of the conditional block.
#
}
#
else
#
{
#
# This is the start of the conditional block.
# Lines before this one are not executed as part of the conditional block.
#
printf ORDER ("\n%4d %-50s %3.2f %3.2f\n",
$quantity, $item, $price, $ext);
#
# This is the end of the conditional block.
# Lines after this one are not executed as part of the conditional block.
#
}
#
Since using this style of braces I have not had this problem even once.
I am currently back porting it to all my code in order to ease
maintenance. Once I have done that I will start sending in patches to
p5p so that all the core Perl modules can be upgraded. I have created a
similar style that is used for C code, and I will eventually patch the
Perl core and Parrot. That should silence those moaning minnies who
complain that the Perl core is impenetrable.
You may be wondering how I will have the time and energy to perform this
service to the community. Well, obviously I won't do it all by hand.
That would be foolish. No, I have created a set of vi macros to assist
in the conversion process. This creates a template for me and during
the 22 seconds it takes to run I am able to decide what I want to put in
the conditional.
I wrote some lisp for emacs but after 43 minutes my swap space was
exhausted and it dumped core. I have attached the core file in case
anyone is able to debug it.
Obviously, there is still work to be done on this methodology.
Consideration needs to be given to for and while loops as a minimum.
However, I have proposed a talk on this at the forthcoming Perl
conference and I am in consultation with a number of publishers as I
feel this new approach to an old problem warrants the publication of a
book. I have, of course, applied for a software patent.
--
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net