rfc:class-naming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
rfc:class-naming [2017/06/03 12:00] – created fleshgrinderrfc:class-naming [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 3: Line 3:
   * Date: 2017-06-03   * Date: 2017-06-03
   * Author: Richard Fussenegger, php@fleshgrinder.com   * Author: Richard Fussenegger, php@fleshgrinder.com
-  * Status: Under Discussion+  * Status: Accepted
   * First Published at: http://wiki.php.net/rfc/class-naming   * First Published at: http://wiki.php.net/rfc/class-naming
  
 ===== Introduction ===== ===== Introduction =====
-The PHP coding standard does not cover how class names should be written. This leads to friction within the userland community that is now largely following the [[http://www.php-fig.org/psr/psr-1/|standard recommendation PSR-1]]. Extending our current coding standard to cover edge cases about abbreviations and acronyms would resolve any future discussion.+The PHP coding standard does not cover how class names should be written. This leads to friction within the userland community that is now largely following the [[http://www.php-fig.org/psr/psr-1/|standard recommendation PSR-1]]. Extending our current coding standard to cover edge cases about abbreviations and acronyms/initialisms would resolve any future discussion.
  
 ===== Proposal ===== ===== Proposal =====
-Extend the coding standard to explicitly specify how abbreviations and acronyms are to be handled when writing user-level class names. The current rule is:+Extend the coding standard to explicitly specify how abbreviations and acronyms/initialisms are to be handled when writing user-level class names. The current rule is:
  
 > Classes should be given descriptive names. Avoid using abbreviations where possible. Each word in the class name should start with a capital letter, without underscore delimiters (CamelCaps starting with a capital letter). The class name should be prefixed with the name of the 'parent set' (e.g. the name of the extension):: > Classes should be given descriptive names. Avoid using abbreviations where possible. Each word in the class name should start with a capital letter, without underscore delimiters (CamelCaps starting with a capital letter). The class name should be prefixed with the name of the 'parent set' (e.g. the name of the extension)::
Line 24: Line 24:
 > — [[https://github.com/php/php-src/blob/abac7e81dd7b2e851562c60377951da5a5a99e30/CODING_STANDARDS#L154-L166|CODING_STANDARD]] > — [[https://github.com/php/php-src/blob/abac7e81dd7b2e851562c60377951da5a5a99e30/CODING_STANDARDS#L154-L166|CODING_STANDARD]]
  
-While it is stated that abbreviations and acronyms should be avoided, it is silent on what to do if they are used. There are essentially three choices possible now:+While it is stated that abbreviations should be avoided, it is silent on what to do if they are used; especially in the case of acronyms/initialisms. There are essentially three choices possible now:
  
-  - **PascalCase except Acronyms** — which is how the majority of user-level class names are written, and it matches the approach of many other programming languages.+  - **PascalCase except Acronyms/Initialisms** — which is how the majority of user-level class names are written, and it matches the approach of many other programming languages.
   - **Always PascalCase** — which is basically what [[http://www.php-fig.org/psr/psr-1/|PSR-1]] defines, however, it would make most of the currently existing user-level class names invalid.   - **Always PascalCase** — which is basically what [[http://www.php-fig.org/psr/psr-1/|PSR-1]] defines, however, it would make most of the currently existing user-level class names invalid.
   - **Do Nothing** — which of course automatically means that any approach is allowed, and the community discussions around this topic will continue.   - **Do Nothing** — which of course automatically means that any approach is allowed, and the community discussions around this topic will continue.
Line 36: Line 36:
 > **IMPORTANT!** > **IMPORTANT!**
  
-==== PascalCase except Acronyms ==== +==== PascalCase except Acronyms/Initialisms ==== 
-> Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the "parent set" (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Abbreviations start with a capital letter followed by lowercase letters, whereas acronyms are all uppercase.+> Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the "parent set" (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms as well as initialisms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Abbreviations start with a capital letter followed by lowercase letters, whereas acronyms and initialisms are written according to their standard notation. Usage of acronyms and initialisms is not allowed if they are not widely adopted and recognized as such.
  
 > Good: > Good:
Line 45: Line 45:
 > 'URL' > 'URL'
 > 'BTreeMap' (B-tree Map) > 'BTreeMap' (B-tree Map)
 +> 'Id' (Identifier)
 +> 'ID' (Identity Document)
 > 'Char' (Character) > 'Char' (Character)
 > 'Intl' (Internationalization) > 'Intl' (Internationalization)
 +> 'Radar' (Radio Detecting and Ranging)
  
 > Bad: > Bad:
Line 54: Line 57:
 > 'Url' > 'Url'
 > 'BtreeMap' > 'BtreeMap'
 +> 'ID' (Identifier)
 > 'CHAR' > 'CHAR'
 > 'INTL' > 'INTL'
 +> 'RADAR' (Radio Detecting and Ranging)
 > >
 > — [[https://github.com/php/php-src/pull/2552|GitHub PR #2552]] > — [[https://github.com/php/php-src/pull/2552|GitHub PR #2552]]
  
 ==== Always PascalCase ==== ==== Always PascalCase ====
-> Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the "parent set" (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Both abbreviations and acronyms follow the same letter-casing as any other word.+> Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the "parent set" (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms as well as initialisms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Abbreviations, acronyms, and initialisms follow the same letter-casing as any other word.
  
 > Good: > Good:
Line 68: Line 73:
 > 'Url' > 'Url'
 > 'BTreeMap' (B-tree Map) > 'BTreeMap' (B-tree Map)
 +> 'Id' (Identifier and Identity Document)
 > 'Char' (Character) > 'Char' (Character)
 > 'Intl' (Internationalization) > 'Intl' (Internationalization)
 +> 'Radar' (Radio Detecting and Ranging)
  
 > Bad: > Bad:
Line 77: Line 84:
 > 'URL' > 'URL'
 > 'BtreeMap' > 'BtreeMap'
 +> 'ID'
 > 'CHAR' > 'CHAR'
 > 'INTL' > 'INTL'
 +> 'RADAR'
  
 > — [[https://github.com/php/php-src/pull/2553|GitHub PR #2553]] > — [[https://github.com/php/php-src/pull/2553|GitHub PR #2553]]
Line 89: Line 98:
  
 ===== Proposed Voting Choices ===== ===== Proposed Voting Choices =====
-Simple 50%+1 majority vote with three options:+Simple 50%+1 majority vote:
  
-  **PascalCase except Acronyms** +<doodle title="Should we update the coding standard?" auth="fleshgrinder" voteType="single" closed="true"> 
-  - **Always PascalCase** +   * Yes 
-  - **Do Nothing**+   * No 
 +</doodle> 
 + 
 +\\ 
 + 
 +<doodle title="What class naming style should we use?" auth="fleshgrinder" voteType="single" closed="true"> 
 +   * PascalCase except Acronyms 
 +   * Always PascalCase 
 +</doodle>
  
 ===== Patches and Tests ===== ===== Patches and Tests =====
   * [[https://github.com/php/php-src/pull/2552|GitHub PR #2552: PascalCase except Acronyms]]   * [[https://github.com/php/php-src/pull/2552|GitHub PR #2552: PascalCase except Acronyms]]
   * [[https://github.com/php/php-src/pull/2553|GitHub PR #2553: Always PascalCase]]   * [[https://github.com/php/php-src/pull/2553|GitHub PR #2553: Always PascalCase]]
 +
 +===== References =====
 +  * [[http://news.php.net/php.internals/99337|Internals Discussion]]
 +  * [[http://news.php.net/php.internals/99241|Internals Pre-Discussion]]
  
rfc/class-naming.1496491243.txt.gz · Last modified: 2017/09/22 13:28 (external edit)