=encoding euc-jp =head1 NAME =begin original perlstyle - Perl style guide =end original perlstyle - Perl �������륬���� =head1 DESCRIPTION =begin original Each programmer will, of course, have his or her own preferences in regards to formatting, but there are some general guidelines that will make your programs easier to read, understand, and maintain. =end original �ץ�����ޤϡ��������ͤ��줾�졢�ե����ޥåȤˤϹ��ߤ�����Ǥ��礦�� �������������Ĥ��Υ����ɥ饤��˽������Ȥˤ�äơ��ץ������β������� �ݼ����򤢤��뤳�Ȥ��Ǥ��ޤ��� =begin original The most important thing is to run your programs under the B<-w> flag at all times. You may turn it off explicitly for particular portions of code via the C pragma or the C<$^W> variable if you must. You should also always run under C or know the reason why not. The C and even C pragmas may also prove useful. =end original ��äȤ���פʤ��Ȥϡ��Ĥͤ˥ץ������� B<-w> �ե饰��Ĥ��� ���餻�뤳�ȤǤ��� ɬ�פǤ���С�C �ץ饰�ޤ� C<$^W> �ѿ�����Ѥ��ƥ����ɤ� ���������Ƿٹ������Ū�˥��դˤ��ޤ��� �ޤ����Ĥͤ� C ����Ѥ��٤��Ǥ��� �⤷��C ����Ѥ��ʤ��ʤ顢������ͳ��ʬ�����򤷤Ƥ����٤��Ǥ��� C �� C �ץ饰�ޤ������Ǥ��礦�� =begin original Regarding aesthetics of code lay out, about the only thing Larry cares strongly about is that the closing curly bracket 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: =end original �����ɥ쥤�����Ȥ����Ѥ˴ؤ��Ƥϡ�Larry ���������ˤ����Ƥ���ΤϤ��ä���ġ� ʣ���Ԥ� BLOCK ���Ĥ��椫�ä��ϡ����ι�¤�򳫻Ϥ���������ɤ�Ʊ�����֤� �ʤ��ƤϤʤ�ʤ��Ȥ������Ȥ����Ǥ��� ������̤Ȥ��ơ������ޤǶ����Ϥʤ���ι��ߤϰʲ����̤�Ǥ�: =over 4 =item * =begin original 4-column indent. =end original 4 �����Υ���ǥ�ȡ� =item * =begin original Opening curly on same line as keyword, if possible, otherwise line up. =end original ��ǽ�ʤ顢�����椫�ä��ȥ�����ɤ�Ʊ��Ԥˡ� �����Ǥʤ���С����Ϥ򤽤����롣 =item * =begin original Space before the opening curly of a multi-line BLOCK. =end original ʣ���� BLOCK �γ����椫�ä������˥��ڡ����� =item * =begin original One-line BLOCK may be put on one line, including curlies. =end original 1 �Ԥ� BLOCK ���椫�ä���ޤᡢ1 �Ԥǡ� =item * =begin original No space before the semicolon. =end original ���ߥ���������˶���ʤ��� =item * =begin original Semicolon omitted in "short" one-line BLOCK. =end original "û��" 1 �� BLOCK �Ǥϥ��ߥ�������ά�� =item * =begin original Space around most operators. =end original �ۤȤ�ɤα黻�Ҥ�����ˤϥ��ڡ����� =item * =begin original Space around a "complex" subscript (inside brackets). =end original "ʣ����"����(�֥饱�å���)������ˤϥ��ڡ����� =item * =begin original Blank lines between chunks that do different things. =end original �ۤʤ뤳�Ȥ򤹤����󥯤δ֤ˤ϶��ԡ� =item * =begin original Uncuddled elses. =end original else �򤯤äĤ��ʤ��� =item * =begin original No space between function name and its opening parenthesis. =end original �ؿ�̾�ȳ��ϥ��å��δ֤ˤϥ��ڡ����ʤ��� =item * =begin original Space after each comma. =end original ����ޤθ���ˤϥ��ڡ����� =item * =begin original Long lines broken after an operator (except C and C). =end original Ĺ���Ԥϡ��黻�Ҥθ���Dz��Ԥ���(C �� C �����)�� =item * =begin original Space after last parenthesis matching on current line. =end original �ԤκǸ�Υ��å��θ���˥��ڡ����� =item * =begin original Line up corresponding items vertically. =end original �б��������Ǥγ��ϰ��֤򤽤����롣 =item * =begin original Omit redundant punctuation as long as clarity doesn't suffer. =end original ��Ĺ��ɽ���ϡ��狼��ˤ����ʤ�ʤ��¤�Ͼ�ά���롣 =back =begin original Larry has his reasons for each of these things, but he doesn't claim that everyone else's mind works the same as his does. =end original Larry �ˤϤ���餽�줾��򹥤���ͳ������ޤ�������ʳ��οͤ�����Ȥޤä��� Ʊ���Ǥ���ɬ�פϤʤ��Ȥ��äƤ��ޤ��� =begin original Here are some other more substantive style issues to think about: =end original ¾�ˡ������פʥ������������򼨤��ޤ�: =over 4 =item * =begin original Just because you I do something a particular way doesn't mean that you I do it that way. Perl is designed to give you several ways to do anything, so consider picking the most readable one. For instance =end original �����򤢤���ˡ�� I<�Ǥ���> ����Ȥ��äơ����� I<���٤�> �Ȥϸ¤�ޤ��� Perl �ϰ�ĤΤ��Ȥ��͡�����ˡ�ǤǤ���褦���߷פ���Ƥ��ޤ����顢��� �ɤߤ䤹����Τ����֤褦�˿������Ƥ��������� ���Ȥ��С� open(FOO,$foo) || die "Can't open $foo: $!"; =begin original is better than =end original �Ȥ����Τϰʲ��Τ�Τ���ɤ��Ǥ�: die "Can't open $foo: $!" unless open(FOO,$foo); =begin original because the second way hides the main point of the statement in a modifier. On the other hand =end original �ʤ��ʤ顢2 ���ܤǤϡ�����ʸ�μ������������Ҥ˱���Ƥ��ޤäƤ��ޤ��� �դˡ� print "Starting analysis\n" if $verbose; =begin original is better than =end original �Ȥ����Τϰʲ��Τ�Τ���ɤ��Ǥ�: $verbose && print "Starting analysis\n"; =begin original because the main point isn't whether the user typed B<-v> or not. =end original ����ʸ�μ������ϡ��桼���� B<-v> �򥿥��פ������ɤ��� �ǤϤʤ�����Ǥ��� =begin original Similarly, just because an operator lets you assume default arguments doesn't mean that you have to make use of the defaults. The defaults are there for lazy systems programmers writing one-shot programs. If you want your program to be readable, consider supplying the argument. =end original Ʊ�ͤˡ�����黻�Ҥ��ǥե���Ȱ��������ꤷ�Ƥ��뤫��Ȥ��äơ����� �ǥե���Ȥ�Ȥ�ʤ��ƤϤʤ�ʤ��Ȥ������ȤˤϤʤ�ޤ��� ���Υǥե�����ͤ�����Τϡ����Ƥʥ����ƥ�ץ�����ޤ�����ȯ�ץ������� �񤯤Ȥ��Τ���ˤ���ޤ��� �ץ��������ɤߤ䤹������ˤϡ��������ά���ʤ��褦�ˤ��ޤ��礦�� =begin original Along the same lines, just because you I omit parentheses in many places doesn't mean that you ought to: =end original Ʊ�ͤˡ�¿���ξ��ǥ��å����ά I<�Ǥ��ޤ�> �����ʲ��Τ褦�� ��ά�������뤳�ȤϹ�����٤��Ǥ��礦: return print reverse sort num values %array; return print(reverse(sort num (values(%array)))); =begin original When in doubt, parenthesize. At the very least it will let some poor schmuck bounce on the % key in B. =end original �¤ä��Ȥ��ϡ����å���񤤤Ƥ��������� ���ʤ��Ȥ⡢�ְ㤨����ʬ�� B �� % �����ǥϥ��饤�Ȥ��뤳�Ȥ��Ǥ��ޤ��� =begin original Even if you aren't in doubt, consider the mental welfare of the person who has to maintain the code after you, and who will probably put parentheses in the wrong place. =end original �¤äƤ��ʤ��Ȥ��⡢���ȤǤ��Υ����ɤ���ƥʥ󥹤���ͤ������ �ͤ��Ƥ��������� �ְ�ä��Ľ�˥��å��򤤤�Ƥ��ޤ����⤷��ޤ��� =item * =begin original Don't go through silly contortions to exit a loop at the top or the bottom, when Perl provides the C operator so you can exit in the middle. Just "outdent" it a little to make it more visible: =end original �롼�פ���Ƭ��������ȴ���Ф��Τˡ��Ф����������ɤ򤫤��ʤ��Ǥ��������� Perl �ˤ� C �黻�Ҥ�����Τǡ������ȴ���Ф����Ȥ��Ǥ��ޤ��� ����äȤ����ɤߤ䤹������ˤ� "�����ȥǥ��" ���ޤ�: LINE: for (;;) { statements; last LINE if $foo; next LINE if /^#/; statements; } =item * =begin original Don't be afraid to use loop labels--they're there to enhance readability as well as to allow multilevel loop breaks. See the previous example. =end original �롼�פΥ�٥���Ѷ�Ū�˻Ȥ��ޤ��礦 -- �������򤢤���Τȶ��ˡ�¿�ʳ��� �롼��ȴ���Ф���Ǥ���褦�ˤʤ�ޤ��� ��ۤɤ���򸫤Ƥ��������� =item * =begin original Avoid using C (or C) or `backticks` in a void context, that is, when you just throw away their return values. Those functions all have return values, so use them. Otherwise use a C loop or the C function instead. =end original C (�� C)���ޤ� `�ե�������` ��̵������ƥ����ȡ��Ĥޤ� �֤��ͤ�̵�뤹��ʸ�ǻ��Ѥ��ʤ��Ǥ��������� �����δؿ��Ϥ��٤��֤��ͤ���äƤ��ޤ����顢�������Ѥ��Ƥ��������� ����ʤ��ΤǤ���С�C �롼�פ� C �ؿ��� ���Ѥ��Ƥ��������� =item * =begin original For portability, when using features that may not be implemented on every machine, test the construct in an eval to see if it fails. If you know what version or patchlevel a particular feature was implemented, you can test C<$]> (C<$PERL_VERSION> in C) to see if it will be there. The C module will also let you interrogate values determined by the B program when Perl was installed. =end original �ݡ����ӥ�ƥ��Τ���ˡ����٤ƤΥޥ���Ǽ�������Ƥ��ʤ����⤷��ʤ���ǽ�� ���Ѥ���ݤϡ������ eval �ǰϤäơ����Ԥ��뤫�ɤ��������å����Ƥ��������� ���뵡ǽ�����ɤΥС�������ѥå���٥�Ǽ�������Ƥ��뤫�ΤäƤ��� ���ˤϡ�C<$]> (C �⥸�塼��Ǥϡ�C<$PERL_VERSION>) �� �����å����뤳�Ȥ�Ǥ��ޤ��� C �⥸�塼���Ȥ��С�Perl ���󥹥ȡ������ C �ץ������� ��äƷ��ꤵ�줿�ͤ�Ĵ�٤뤳�Ȥ��Ǥ��ޤ��� =item * =begin original Choose mnemonic identifiers. If you can't remember what mnemonic means, you've got a problem. =end original �ˡ���˥å��ʼ��̻Ҥ�����Ǥ��������� ���Υˡ���˥å��������̣���뤫�פ��Ф��ʤ���С�����Ǥ��� =item * =begin original While short identifiers like C<$gotit> are probably ok, use underscores to separate words in longer identifiers. It is generally easier to read C<$var_names_like_this> than C<$VarNamesLikeThis>, especially for non-native speakers of English. It's also a simple rule that works consistently with C. =end original C<$gotit> �Τ褦��û�����̻Ҥʤ� ok �Ǥ��������Ĺ�����̻Ҥ�ñ��� ���ڤ�ˤϥ����������������Ѥ��Ƥ��������� ����Ū�ˤϡ��Ȥ��˱Ѹ�Υͥ��ƥ��֥��ԡ������Ǥʤ��ͤˤȤäƤϡ� C<$var_names_like_this> ������ C<$VarNamesLikeThis> ����ɤߤ䤹���Ǥ��� ���Υ롼��� C �ˤĤ��Ƥ�Ʊ�ͤ����ƤϤޤ�ޤ��� =begin original Package names are sometimes an exception to this rule. Perl informally reserves lowercase module names for "pragma" modules like C and C. Other modules should begin with a capital letter and use mixed case, but probably without underscores due to limitations in primitive file systems' representations of module names as files that must fit into a few sparse bytes. =end original �ѥå�����̾�ϡ����Υ롼����㳰�ˤʤ뤳�Ȥ�����ޤ��� Perl �Ͼ�ʸ���Υ⥸�塼��̾��C �� C �Τ褦��"�ץ饰��" �⥸�塼��Τ����ͽ�󤷤Ƥ��ޤ��� ����¾�Υ⥸�塼�����ʸ������Ϥ���ơ���ʸ���򺮤��ƻ��Ѥ��٤��Ǥ����� ��������������ϻ��Ѥ��ޤ��� �ץ�ߥƥ��֤ʥե����륷���ƥ�Ǥϡ��⥸�塼��̾��ե�����Ȥ��� ɽ������ݤˡ��Х��ȿ������¤����뤿��Ǥ��� =item * =begin original You may find it helpful to use letter case to indicate the scope or nature of a variable. For example: =end original �ѿ��Υ������פ�������ɽ������Τˡ���ʸ����ʸ����Ȥ��������Ǥ��礦�� ���Ȥ���: =begin original $ALL_CAPS_HERE constants only (beware clashes with perl vars!) $Some_Caps_Here package-wide global/static $no_caps_here function scope my() or local() variables =end original $ALL_CAPS_HERE ����Τ� (perl �ѿ��Ȥξ��ͤ�����!) $Some_Caps_Here �ѥå������磻�ɤʥ������Х�/�����ƥ��å��ѿ� $no_caps_here �ؿ��������פ� my(),local()�ѿ� =begin original Function and method names seem to work best as all lowercase. E.g., C<$obj-Eas_string()>. =end original �ؿ��ȥ᥽�åɤ�̾���Ϥ��٤ƾ�ʸ�����ȥ٥��ȤǤ��� �㤨�С�C<$obj-Eas_string()>�� =begin original You can use a leading underscore to indicate that a variable or function should not be used outside the package that defined it. =end original ��Ƭ�˥��������������Ĥ��뤳�Ȥˤ�äơ��ѿ���ؿ�����������ѥå��������� ���Ѥ��٤��Ǥʤ����Ȥ򼨤����Ȥ��Ǥ��ޤ��� =item * =begin original If you have a really hairy regular expression, use the C modifier and put in some whitespace to make it look a little less like line noise. Don't use slash as a delimiter when your regexp has slashes or backslashes. =end original �ۤ�Ȥˤ����㤴���������ɽ����Ȥ����ˤϡ�C �����Ҥ���Ѥ��� ���ڡ����򤤤졢���ߤߤ����ˤʤ�ʤ��褦�ˤ��Ƥ��������� ����ɽ����˥���å����Хå�����å��夬����Ȥ��ˤϡ��ǥ�ߥ��� ����å����Ȥ�ʤ��褦�ˡ� =item * =begin original Use the new C and C operators to avoid having to parenthesize list operators so much, and to reduce the incidence of punctuation operators like C<&&> and C<||>. Call your subroutines as if they were functions or list operators to avoid excessive ampersands and parentheses. =end original ������ C �� C �黻�Ҥ���Ѥ����ꥹ�ȱ黻�ҤΥ��å������������ �ʤä��ꡢC<&&> �� C<||> ������ȯ������Τ��򤱤Ƥ��������� ���֥롼����ϡ��ؿ���ꥹ�ȱ黻�ҤǤ��뤫�Τ褦�˰���������ѥ���ɤ� ���å�������ȯ������Τ��򤱤Ƥ��������� =item * =begin original Use here documents instead of repeated C statements. =end original C ʸ�򷫤��֤������ҥ��ɥ�����Ȥ���Ѥ��Ƥ��������� =item * =begin original Line up corresponding things vertically, especially if it'd be too long to fit on one line anyway. =end original �б������Τγ��ϰ��֤Ϥ������Ƥ����������Ȥ��ˡ�1�Ԥˤ����ޤ�ʤ���Τ� �ؤ��ơ� $IDX = $ST_MTIME; $IDX = $ST_ATIME if $opt_u; $IDX = $ST_CTIME if $opt_c; $IDX = $ST_SIZE if $opt_s; mkdir $tmpdir, 0700 or die "can't mkdir $tmpdir: $!"; chdir($tmpdir) or die "can't chdir $tmpdir: $!"; mkdir 'tmp', 0777 or die "can't mkdir $tmpdir/tmp: $!"; =item * =begin original Always check the return codes of system calls. Good error messages should go to C, include which program caused the problem, what the failed system call and arguments were, and (VERY IMPORTANT) should contain the standard system error message for what went wrong. Here's a simple but sufficient example: =end original �����ƥॳ������֤ꥳ���ɤϤĤͤ˥����å����Ƥ��������� �ɤ����顼��å������� C �˽񤭽Ф��졢�����ȯ�������� �ץ������̾�䡢���Ԥ��������ƥॳ����Ȱ�����������(�ȤƤ����)ɸ�� �����ƥ२�顼��å�������ޤ�٤��Ǥ��� �ʲ��ϥ���ץ�Ǥ�������ʬ����Ǥ�: opendir(D, $dir) or die "can't opendir $dir: $!"; =item * =begin original Line up your transliterations when it makes sense: =end original ���䤹���ʤ���ˤϡ�tr �γ��ϰ��֤򤽤����Ƥ��������� tr [abc] [xyz]; =item * =begin original Think about reusability. Why waste brainpower on a one-shot when you might want to do something like it again? Consider generalizing your code. Consider writing a module or object class. Consider making your code run cleanly with C and C (or B<-w>) in effect. Consider giving away your code. Consider changing your whole world view. Consider... oh, never mind. =end original �����������θ���ޤ��礦�� Ʊ�����Ȥ򤢤ȤǤ�뤫�⤷��ʤ��Ȥ��ˡ�Ǿ���Ϥ��ȯ�Υץ������� ̵�̤ˤ���ɬ�פϤ���ޤ���? �����ɤΰ��̲����θ�����⥸�塼��䥪�֥������ȥ��饹��񤯤��Ȥ� ��θ���ޤ��礦�� �����ɤ� C �� C (���뤤�� B<-w>) ��ͭ���Ǥ� �������ư������θ���ޤ��礦�� �����ɤ�ΤƵ�뤳�Ȥ��θ���ޤ��礦�� �����θ������Ѥ��뤳�Ȥ��θ���ޤ��礦�� ¾�ˤ�ġĤ������⤦�����䡣 =item * =begin original Try to document your code and use Pod formatting in a consistent way. Here are commonly expected conventions: =end original ���ʤ��Υ����ɤ�ʸ�񲽤��ơ���Ӥ�����ˡ�� Pod �ե����ޥåȤ�Ȥ��褦�� ���Ϥ��Ƥ��������� �ʲ��Ϲ������ꤵ��Ƥ��봷���Ǥ�: =over 4 =item * =begin original use CE> for function, variable and module names (and more generally anything that can be considered part of code, like filehandles or specific values). Note that function names are considered more readable with parentheses after their name, that is C. =end original �ؿ�̾���ѿ�̾���⥸�塼��̾(����Ӥ�����Ū�ˤϡ��ե�����ϥ�ɥ�� ������ͤΤ褦�ʡ������ɤΰ����ȹͤ�������)�ˤ� CE> �� �ȤäƤ��������� �ؿ�̾�ϡ�C �Τ褦�ˡ�̾���θ���ˤ��ä����դ���� ����ɤߤ䤹���ʤ�ȹͤ����Ƥ��ޤ��� =item * =begin original use CE> for commands names like B or B. =end original B �� B �Τ褦�ʥ��ޥ��̾�ˤ� CE> ��ȤäƤ��������� =item * =begin original use CE> or CE> for file names. CE> should be the only Pod code for file names, but as most Pod formatters render it as italic, Unix and Windows paths with their slashes and backslashes may be less readable, and better rendered with CE>. =end original �ե�����̾�ˤ� CE> �� CE> ��ȤäƤ��������� CE> �ϥե�����̾�Τ����ͣ��� Pod �����ɤǤ���٤��Ǥ����� �ۤȤ�ɤ� Pod �ե����ޥå��Ϥ���򥤥���å��Τ�ɽ�����뤿�ᡢ Unix �� Windows �ǥѥ��˻Ȥ��륹��å����ե���å��夬�ɤߤˤ����Ǥ�; CE> �Ϥ��褯ɽ������ޤ��� =back =item * =begin original Be consistent. =end original �Ĥͤ˰������ =item * =begin original Be nice. =end original �Ĥͤ���Ũ�ˡ� =back =begin meta Translate: Tatsuhiko Miyagawa (5.8.0) Update: SHIRAKATA Kentaro (5.10.0-) Status: completed =end meta