Apologies if this is old hat... It seems that a lot of the responses missed the point.
Whether your intended style is this: if (...) { ... } else { ... } or this: if (...) { ... } else { ... } or this: if (...) { ... } else { ... } or a variation of those, or even one of the other styles, it is still too easy to do this: if (...) { ... } else { printf ORDER ("\n%4d %-50s %3.2f %3.2f\n", } $quantity, $item, $price, $ext); # ^ # | # +---- bitten again Changing the indent style is looking at the horizontal alignment of the braces. The real issue is the *vertical* alignment of the braces. Even a "brace flasher" editor doesn't help, because the opening brace is highlighted, which is not usually a problem. I don't care for this: if (...) { ... } else { ... } because it solves one problem and creates another. Unfortunately for all of us, Paul Johnson's solution is the only one I've seen that exiles this problem to the "less likely" list. Unfortunate, because perhaps 10 more problems are elevated to the "more likely" list. [It *was* good for a chuckle here though ;] Note that "use BraceBeGone" neglected an "endif", making the rest of the program conditional [i.e., the runtime speedup may be enormous]. Perhaps what we need is an inverted if-else, such as this: { ... } if (...) else { ... } However, that is hard to distinguish visually from this: { ... } if (...); { ... } Now if someone where to come up with a Crisp- or Emacs- or Vim-like macro to recolor successively nested clauses, we might have a chance. Except I'm sure everyone on this list is wearing their Perl.Org (tm) Rose-Colored Monitor Glasses, so the obfuscation contest may have some very creative (if inadvertent) entries this year. -Shaun Quantum Mechanics: The dreams stuff is made of -----Original Message----- From: Paul Johnson [mailto:[EMAIL PROTECTED]] Sent: Friday, February 22, 2002 1:35 PM To: Keith C. Ivey Cc: Fun With Perl Subject: Re: Fwd: Re: interesting typo I couldn't see 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