At 06:05 PM 6/26/01 -0400, Gross, Stephan wrote:
>Why is this style
>
>if ($x) {
>     do this;
>     do that;
>}
>
>typically preferred over
>
>if ($x)
>{
>    do this;
>    do that;
>}
>

This tends to be a hotly debated religious issue.  There are people who use 
that later abomination.  ;-)  The closest I can come to a rationalization 
for my preference is that the former is easier to visually scan.  You see 
the if token and then it is indented to a close-squiggly that appears by 
itself.  For me at least, the
{
    ...
}
scans as a completely separate entity and sets me looking for funny tricks 
with scopes or closures or something.

Of course, the reason that it scans that way for me is that I never write 
that way, nor have I ever worked with anyone who made it their habit.  I 
think my reason for preferring it boils down to the fact that it is the way 
I've always done it.

>I like the latter example because it's easier to cut and paste the braces
>and everything in between.

Mmmm...  Same for me either way:
y%
does it in vim in either case.  If you use the former technique, you'll type:
$y%
a lot and if the latter:
jy%
often.  I imagine the same is true in emacs, though it'll be a little 
harder on your pinky.  ;-)

If you are using something that makes you highlight a section with a mouse 
in order to copy it, you're already slowing yourself down 
needlessly.  Switch to something key-based and you'll find that you speed 
up to the point where placement of braces won't be so important to speed.

Actually, I have encountered one custom that slowed me down 
considerably.  It was a variation on the first of your above techniques, 
but the miserable sod put a space after the opening brace in if and loop 
statements.

That breaks $y% or just $%.  They still haven't found his body and all of 
his code has been repaired.

Cheers,
Jeff



Reply via email to