Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How should abbreviations and acronyms be written? #83

Open
boan-jfm opened this issue Oct 23, 2023 · 11 comments
Open

How should abbreviations and acronyms be written? #83

boan-jfm opened this issue Oct 23, 2023 · 11 comments

Comments

@boan-jfm
Copy link

We have a recommendation to use StudlyCaps (PascalCase) naming in the PER:

PER

The term "StudlyCaps" in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter.
-- https://www.php-fig.org/per/coding-style/#2-general

Class names

Class names MUST be declared in StudlyCaps
-- https://www.php-fig.org/psr/psr-1/#3-namespace-and-class-names

Method names

Method names MUST be declared in camelCase().
-- https://www.php-fig.org/psr/psr-1/#43-methods

But how should we write abbreviations and acronyms?

I suggest following camel case, e.g., loadHttpUrl as recommended in the "Google TypeScript Style Guide".

Google TypeScript Style Guide:

5.1.3 Camel case
Treat abbreviations like acronyms in names as whole words, i.e. use loadHttpUrl, not loadHTTPURL, unless required by a platform name (e.g. XMLHttpRequest).
-- https://google.github.io/styleguide/tsguide.html#camel-case

@vjik
Copy link
Contributor

vjik commented Oct 23, 2023

In Yii3 we use camel case:

Names
Use camelCase notation, including abbreviations (e.g., enableIdn).

@Crell
Copy link
Collaborator

Crell commented Oct 23, 2023

At present there is no standard, I believe. I've seen people say Internals has one for PHP, but it's not followed consistently. (I forget off hand which way it goes, honestly.)

Were we to adopt anything, it should follow what Internals does. That means knowing what Internals wants to do. 😄

@imme-emosol
Copy link

About a class naming convention.

My preference would be to recommend
using underscore to separate all-caps-word-groups (such as: abbreviations, acronyms) .

Readability : using underscore as a separator for all-caps-word-groups used in class names ,
gives me a quicker distinction of the all-caps-word-groups used when reading the text .

Variety : using underscore as a separator for all-caps-word-groups in class names ,
allows using combined all-caps-word-groups with other (combined) all-caps-word-groups .

To my knowledge ,
an underscore in class names in code written for PHP 5.3 and after
does not have additional meaning
( while before 5.3 does : https://www.php-fig.org/psr/psr-1/#3-namespace-and-class-names ) .

Examples

Some (hypothetical) class name examples with all-caps-word-groups .
Where a all-caps-word-group is one or more all-caps-words .

XML HTTP Request

An XML HTTP Request - extensible markup language - hyper text transfer protocol - request .

With lowercasing it could be made clear :
XmlhttpRequest , XmlHttpRequest .

With underscore as separator it could be made clear :
XMLHTTP_Request , XML_HTTPRequest , XML_HTTP_Request .

With the combination it could be made clear :
XmlHttp_Request , Xml_HttpRequest , Xml_Http_Request .

{SMS ,SM S}API Input

A
SMS API Input - short message service - application programming interface - input , or
SM SAPI Input - short message - server application programming interface - input .

With underscore as abbreviation separator it could be made clear :
SMS_API_Input , SMS_APIInput , SM_SAPI_Input , SM_SAPIInput
(not so with : SMSAPIInput , SMSAPI_Input ) .

With lowercasing it could be made clear :
SmsApiInput , SmSapiInput
( not so with : SmsapiInput ) .

X{, }S{, }L{, }T Processor

A
XSLT Processor - extensible stylesheet language transformations - processor , or
XSL T Processor - extensible stylesheet language - tokenization - processor , or
XS LT Processor - external service - language transformations - processor , or
XS L T Processor - external service - language - t... - processor ,
et cetera.

With underscore as separator it could be made clear :
XSL_T_Processor , XS_LT_Processor or XSLT_Processor .
With lowercasing it could be made clear :
XslTProcessor , XsLtProcessor , XsltProcessor .

@imme-emosol
Copy link

Current PHP (inconsistencies)

Regarding the "standard [..] for PHP [..] not followed consistently" these pages https://www.php.net/manual/en/reserved.interfaces.php , https://www.php.net/manual/en/reserved.classes.php , https://www.php.net/manual/en/refs.xml.php show some inconsistent naming of classes.
Some examples of names that stick out : stdClass (first letter in lowercase) , php_user_filter (use of snake_case / lowercase & underscore) , Spl* , Intl* , LibXMLError vs. DOM* , {Simple,}XML* etc. (capitalized vs. non-capitalized)

@imme-emosol
Copy link

At present there is no standard, I believe. I've seen people say Internals has one for PHP, but it's not followed consistently. (I forget off hand which way it goes, honestly.)

Were we to adopt anything, it should follow what Internals does. That means knowing what Internals wants to do. 😄

Is it (PER-working group) policy to follow any standard used by PHP Internals ?

@Crell
Copy link
Collaborator

Crell commented Apr 4, 2024

We have no official stance, as a WG or as FIG, on following Internals conventions. Though Internals conventions are indeed one factor we should consider among many.

@Crell
Copy link
Collaborator

Crell commented Apr 4, 2024

Update: Internals adopted a standard for new classes in 2017, that uses PascalCase except for Acronyms. https://wiki.php.net/rfc/class-naming

So HTTPStatusCode, URL, BTreeMap, etc.

It would be logical to follow suit for user-space.

@imme-emosol
Copy link

imme-emosol commented Apr 4, 2024

Combinations of Acronyms/Initialisms, such as HTTPXMLRequest seem to be omitted from that RFC.

Neither is such a thing mentioned in php/php-src#2552 (comment) its file changes.

What that change does mention is the following.

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.

@TimWolla
Copy link
Contributor

TimWolla commented Apr 5, 2024

For reference: https://news-web.php.net/php.internals/122975.

@vdelau
Copy link
Member

vdelau commented Apr 18, 2024

Were this to be added to the PER, I would classify such conventions as 'highly recommended', so as SHOULD level requirements. I would not make it MUST level requirements, as there are a lot of edge cases or alignment with other systems (the XMLHttpRequest example for instance).

For FIGs own artifacts, there is also the bylaws to consider: https://www.php-fig.org/bylaws/psr-naming-conventions/
I can imagine that needs an update anyway to refer to the PER instead of PSR-12 and could than also require a more strict naming convention.

@TimWolla
Copy link
Contributor

TimWolla commented May 8, 2024

Updated php-src policy merged in php/php-src#14169.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants