cvs: peardoc /peardoc2/fr/chapters standards.xml

From: Date: Tue, 11 Mar 2003 21:38:11 +0000
Subject: cvs: peardoc /peardoc2/fr/chapters standards.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-441@lists.php.net to get a copy of this message
thierry_bo Tue Mar 11 16:38:11 2003 EDT Added files: /peardoc/peardoc2/fr/chapters standards.xml Log: + initial commit (partially translated)

Index: peardoc/peardoc2/fr/chapters/standards.xml +++ peardoc/peardoc2/fr/chapters/standards.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <!-- Translation reference : en version v1.3 --> <chapter id="standards"> <title>Style de Codage</title> <note> <simpara> Le Style de Codage PEAR s'applique à tout le code qui fait partie de la distribution officielle de PEAR (soit distribué avec PHP, soit disponible en téléchargement depuis les archives PHP PEAR). </simpara> </note> <sect1 id="standards.indenting"> <title>Indentation</title> <para> Utilisez une indentation de 4 espaces, sans tabulation. Si vous utilisez Emacs pour éditer le code PEAR, vous devez fixer le paramètre indent-tabs-mode à 'nil'. Vous trouverez ici un exemple de configuration de Emacs pour respecter ces recommendations (vous devrez vous assurer qu'elle est bien appelée lorsque vous éditerez les fichiers PEAR): <programlisting role="elisp"> (defun php-mode-hook () (setq tab-width 4 c-basic-offset 4 c-hanging-comment-ender-p nil indent-tabs-mode (not (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name)) (string-match "\.php$" (buffer-file-name)))))) </programlisting> </para> <para>De la même façon, vous trouverez ici les règles pour vim : <programlisting role="vim"> set expandtab set shiftwidth=4 set softtabstop=4 set tabstop=4 </programlisting> </para> </sect1> <sect1 id="standards.control"> <title>Structures de Contrôles</title> <para> Les structures de contrôles incluent les 'if', 'for', 'while', 'switch', etc. Vous trouverez ici un exemple de structure 'if' qui est la plus compliquée : <programlisting role="php"> if ((condition1) || (condition2)) { action1; } elseif ((condition3) &amp;&amp; (condition4)) { action2; } else { defaultaction; } </programlisting> </para> <simpara> Les instructions de contrôle doivent avoir un espace entre le mot clé de l'instruction et la parenthèse ouvrante, afin de ne pas les confondre avec des appels de fonction. </simpara> <simpara> Il est vivement recommandé de toujours utiliser des parenthèses, même dans les situations où elles sont techniquement optionnelles. Leur présence augmente la lisibilité du code et réduit le risque d'erreur logique lors de l'ajout de nouvelles lignes de code. </simpara> <para> Pour l'instruction "switch" : <programlisting role="php"> switch (condition) { case 1: action1; break; case 2: action2; break; default: defaultaction; break; } </programlisting> </para> </sect1> <sect1 id="standards.funcalls"> <title>Appels de Fonction</title> <para> Les fonctions doivent être appelées sans espace entre le nom de la fonction, la parenthèse ouvrante, et le premier paramètre; avec un espace entre la virgule et chaque paramètre; et aucun espace entre le dernier paramètre, la parenthèse fermante et le point virgule. Voici un exemple : <programlisting role="php"> $var = foo($bar, $baz, $quux); </programlisting> </para> <para> Comme montré ci-dessus, il doit y avoir un espace de chaque côté du signe égal utilisé pour affecter la valeur de retour de la fonction à une variable. Dans le cas d'un bloc d'instructions similaire, des espaces supplémentaires peuvent être ajoutés pour améliorer la lisibilité : <programlisting role="php"> $short = foo($bar); $long_variable = foo($baz); </programlisting> </para> </sect1> <sect1 id="standards.funcdef"> <title>Définitions des Fonctions</title> <para> La déclaration des fontions respecte l'indentation classique des accolades : <programlisting role="php"> function fooFunction($arg1, $arg2 = '') { if (condition) { statement; } return $val; } </programlisting> </para> <para> Les arguments possèdant des valeurs par défaut vont à la fin de la liste des arguments. Il faut toujours chercher à retourner une valeur ayant un sens lorsque cela est possible. Voici un exemple un peu plus long : <programlisting role="php"> function connect(&amp;$dsn, $persistent = false) { if (is_array($dsn)) { $dsninfo = &amp;$dsn; } else { $dsninfo = DB::parseDSN($dsn); } if (!$dsninfo || !$dsninfo['phptype']) { return $this->raiseError(); } return true; } </programlisting> </para> </sect1> <sect1 id="standards.comments"> <title>Commentaires</title> <para> Inline documentation for classes should follow the PHPDoc convention, similar to Javadoc. More information about PHPDoc can be found here: <ulink url="&url.phpdoc;">&url.phpdoc;</ulink> </para> <para> Non-documentation comments are strongly encouraged. A general rule of thumb is that if you look at a section of code and think "Wow, I don't want to try and describe that", you need to comment it before you forget how it works. </para> <para> C style comments (/* */) and standard C++ comments (//) are both fine. Use of Perl/shell style comments (#) is discouraged. </para> </sect1> <sect1 id="standards.including"> <title>Including Code</title> <para> Anywhere you are unconditionally including a class file, use <function>require_once</function>. Anywhere you are conditionally including a class file (for example, factory methods), use <function>include_once</function>. Either of these will ensure that class files are included only once. They share the same file list, so you don't need to worry about mixing them - a file included with <function>require_once</function> will not be included again by <function>include_once</function>. <note> <simpara> <function>include_once</function> and <function>require_once</function> are statements, not functions. You don't <emphasis>need</emphasis> parentheses around the filename to be included. </simpara> </note> </para> </sect1> <sect1 id="standards.tags"> <title>PHP Code Tags</title> <para> <emphasis>Always</emphasis> use <literal>&lt;?php ?></literal> to delimit PHP code, not the <literal>&lt;? ?></literal> shorthand. This is required for PEAR compliance and is also the most portable way to include PHP code on differing operating systems and setups. </para> </sect1> <sect1 id="standards.header"> <title>Header Comment Blocks</title> <para> All source code files in the core PEAR distribution should contain the following comment block as the header: <programlisting role="php"> /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Original Author &lt;author@example.com> | // | Your Name &lt;you@example.com> | // +----------------------------------------------------------------------+ // // &dollar;Id&dollar; </programlisting> </para> <para> There's no hard rule to determine when a new code contributor should be added to the list of authors for a given source file. In general, their changes should fall into the "substantial" category (meaning somewhere around 10% to 20% of code changes). Exceptions could be made for rewriting functions or contributing new logic. </para> <para> Simple code reorganization or bug fixes would not justify the addition of a new individual to the list of authors. </para> <para> Files not in the core PEAR repository should have a similar block stating the copyright, the license, and the authors. All files should include the modeline comments to encourage consistency. </para> </sect1> <sect1 id="standards.cvs"> <title>Using CVS</title> <simpara> This section applies only to packages using CVS at cvs.php.net. </simpara> <para> Include the &dollar;Id&dollar; CVS keyword in each file. As each file is edited, add this tag if it's not yet present (or replace existing forms such as "Last Modified:", etc.). <!-- <note> <simpara> We have a custom $Horde tag in Horde cvs to track our versions separately; we could do the same and make a $PEAR tag, that would remain even if PEAR files were put into another source control system, etc...] </simpara> </note> --> </para> <para> The rest of this section assumes that you have basic knowledge about CVS tags and branches. </para> <para> CVS tags are used to label which revisions of the files in your package belong to a given release. Below is a list of the required and suggested CVS tags: <variablelist> <varlistentry> <term>RELEASE_<replaceable>n_n</replaceable></term> <listitem> <simpara> (required) Used for tagging a release. If you don't use it, there's no way to go back and retrieve your package from the CVS server in the state it was in at the time of the release. </simpara> </listitem> </varlistentry> <varlistentry> <term>QA_<replaceable>n_n</replaceable></term> <listitem> <simpara> (branch, optional) If you feel you need to roll out a release candidate before releasing, it's a good idea to make a branch for it so you can isolate the release and apply only those critical fixes before the actual release. Meanwhile, normal development may continue on the main trunk. </simpara> </listitem> </varlistentry> <varlistentry> <term>MAINT_<replaceable>n_n</replaceable></term> <listitem> <simpara> (branch, optional) If you need to make "micro-releases" (for example 1.2.1 and so on after 1.2), you can use a branch for that too, if your main trunk is very active and you want only minor changes between your micro-releases. </simpara> </listitem> </varlistentry> </variablelist> Only the RELEASE tag is required, the rest are recommended for your convenience. </para> <para> Below is an example of how to tag the 1.2 release of the "Money_Fast" package: <informalexample> <screen><prompt>$ </prompt><command>cd pear/Money_Fast</command> <prompt>$ </prompt><command>cvs tag RELEASE_1_2</command> <computeroutput>T Fast.php T README T package.xml </computeroutput> </screen> </informalexample> By doing this you make it possible for the PEAR web site to take you through the rest of your release process. </para> <para> Here's an example of how to create a QA branch: <informalexample> <screen><prompt>$ </prompt><command>cvs tag QA_2_0_BP</command> ... <prompt>$ </prompt><command>cvs rtag -b -r QA_2_0_BP QA_2_0</command> <prompt>$ </prompt><command>cvs update -r QA_2_0</command> <prompt>$ </prompt><command>cvs tag RELEASE_2_0RC1</command> ...and then the actual release, from the same branch: <prompt>$ </prompt><command>cvs tag RELEASE_2_0</command> </screen> </informalexample> The "QA_2_0_BP" tag is a "branch point" tag, which is the start point of the tag. It's always a good idea to start a CVS branch from such branch points. MAINT branches may use the RELEASE tag as their branch point. </para> </sect1> <sect1 id="standards.exampleurls"> <title>Example URLs</title> <para> Use "example.com", "example.org" and "example.net" for all example URLs and email addresses, per RFC 2606. </para> </sect1> <sect1 id="standards.naming"> <title>Naming Conventions</title> <sect2> <title>Classes</title> <para> Classes should be given descriptive names. Avoid using abbreviations where possible. Class names should always begin with an uppercase letter. The PEAR class hierarchy is also reflected in the class name, each level of the hierarchy separated with a single underscore. Examples of good class names are: <informaltable> <tgroup cols="3"> <tbody> <row> <entry><simpara>Log</simpara></entry> <entry><simpara>Net_Finger</simpara></entry> <entry><simpara>HTML_Upload_Error</simpara></entry> </row> </tbody> </tgroup> </informaltable> </para> </sect2> <sect2> <title>Functions and Methods</title> <para> Functions and methods should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). Functions should in addition have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized. Some examples: <informaltable> <tgroup cols="4"> <tbody> <row> <entry><simpara>connect()</simpara></entry> <entry><simpara>getData()</simpara></entry> <entry><simpara>buildSomeWidget()</simpara></entry> <entry><simpara>XML_RPC_serializeData()</simpara></entry> </row> </tbody> </tgroup> </informaltable> </para> <para> Private class members (meaning class members that are intented to be used only from within the same class in which they are declared; PHP does not yet support truly-enforceable private namespaces) are preceded by a single underscore. For example: <informaltable> <tgroup cols="3"> <tbody> <row> <entry><simpara>_sort()</simpara></entry> <entry><simpara>_initTree()</simpara></entry> <entry><simpara>$this->_status</simpara></entry> </row> </tbody> </tgroup> </informaltable> </para> </sect2> <sect2> <title>Constants</title> <para> Constants should always be all-uppercase, with underscores to separate words. Prefix constant names with the uppercased name of the class/package they are used in. For example, the constants used by the <literal>DB::</literal> package all begin with "<literal>DB_</literal>". </para> </sect2> <sect2> <title>Global Variables</title> <para> If your package needs to define global variables, their name should start with a single underscore followed by the package name and another underscore. For example, the PEAR package uses a global variable called $_PEAR_destructor_object_list. </para> </sect2> </sect1> </chapter> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#441) next »