田口 浩 wrote:
> Hello,
> 
> The code below is in the Camel book, and I like this style.
> Anyone knows the name of this style or there is no such a name?
> 
> ----------------------------
> if    (/^abc/) { $abc = 1 }
> elsif (/^def/) { $def = 1 }
> elsif (/^xyz/) { $xyz = 1 }
> else           { $nothing = 1 }
> ----------------------------
> 
> I know K&R and BSD/Allman style refering to the IF style,
> but this is not these.
> I can't remember someone was calling it as...

Just for another opinion, I prefer to not waste my time typing and lining
things up when I can use that time writing and testing the code itself.
Of course it's a matter of preference, but the easier it is to both read
and modify make it easier to maintain.

Give me K&R style any day - it's less time consuming to write and easier
to later modify (adding the ;'s also helps to modify later):

        if (/^abc/) {
                $abc = 1;
        } elsif (/^def/) {
                $def = 1;
        } elsif (/^xyz/) {
                $xyz = 1;
        } else {
                $nothing = 1;
        }

Easy to add another line of code (or more) on any else condition
before or after the existing line.

This could also be acceptable, but why compress it when it's easier
to read the above (notice the close brace '}' is not on the end of
line, but in the K&R position on the next line):

        if (/^abc/) { $abc = 1;
        } elsif (/^def/) { $def = 1;
        } elsif (/^xyz/) { $xyz = 1;
        } else { $nothing = 1;
        }

I'm also not a fan of this style of indenting:

        if (something)
        {
                do stuff
        }

Just a waste of a line with the {.

Another important aspect of style is to always end a line thats being
continued with something that makes it obvious there is a continuation
line.

EG:
        my $Workbook = $excel_app->Workbooks->Add({ Template => $path }) or
          die "open $path: $! ($^E)";

The or on the end of the 1st line makes it obvious there is a second
line - wheras if you move the or to the beginning of the next line as
many do, I find it harder to read.

        $msg->attach(Type => 'image/jpeg', Path => $file, Filename => $file,
          Disposition => 'attachment') or die "attach $file: $! ($^E)";

The comma on the end of line 1 makes it obvious there is a line 2.  You
could break at the => also, but it's nicer to keep the paired terms
together if you can.


A comma or other obvious operator are good choices whereas a close paren
')' would be an example of a poor choice since it shows closure.

Let's hope this doesn't start a flame war.

The only time it makes any sense at all to line things up for me would
be variable/constant definitions.
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to