-
Notifications
You must be signed in to change notification settings - Fork 40
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
docblocks coding standard: NULL, FALSE, TRUE or null, false, true #6014
Comments
Yeah, it's annoying to have inconsistencies in core. I don't mind one way or the other whether we decide to use uppercase or lowercase. I just want to make sure we settle on something so our standards are properly documented and then we can fix places in core that don't conform. |
Type-hinting in PHP documentation use lowercase characters, in documentation comments or in code. We should use lowercase characters for them too. |
PHP documentation is all over the place. Whether by intention or not, https://www.php.net/manual/en/language.types.boolean.php uses:
All within the same short page. Though it does seem like they have a preference for The Type Declarations indicates lower-case I could see benefits either way. We're already using all uppercase in most places, so I'd be inclined to go that way. |
Actually, Booleans is not about type hinting, but values to assign to variables, since it shows examples like Type declarations is relevant for how types are declared (and which types are allowed). |
I don't have any strong preference, but as I also mentioned in the dev meeting today, having everything be uppercase makes it easier to remember and less for newcomers to remember as an "exception". Consider this guide:
vs. this one:
|
I was looking at what CiviCRM does (officially it follows the Drupal code standards but not consistently) and found a mention here civicrm/civicrm-core#22515 of the FIG standards PSR-5, and that CiviCRM was changing the uppercase to lower. php-fig describes them as "keywords": "A keyword defines the purpose of this type." And some of the keywords:
...
...
I was leaning uppercase (it is easier to explain), but now I'm fine with just leaving the Backdrop standard as-is on this matter and fixing the code instead. I can see there is some logic to making the type keyword lowercase and then differentiating it from the value that gets assigned to the variable. Plus PSR-5 and Drupal standard uses lowercase so it doesn't hurt to be consistent with that. Not that it's that difficult to read either way. (It is easier to remember to always write all-caps but we'll probably get used to the two different ways). So this means we'll need to write docblocks like:
We'll just have to be able to explain that the first |
I'm fine with that ^^ as well Not being helpful, I know 😅 ...but I'm basically with what @BWPanda said: make a decision and then either fix our coding standards, or fix the code (or both). |
I was also thinking it might make things more confusing if we change some data types to uppercase and leave others as lowercase:
As it is now, all the data types listed on that page are lowercase 👍 So if we don't mind leaving the standards as they are, that's the easiest route (no need to update documentation, and existing code is already being fixed in #6004)... Shall we close this as 'works as designed' then? |
Thanks @kiamlaluno, @herbdool, and @BWPanda for the additional context. That really helps push me into the direction of keeping docblock keywords as all lowercase. I'm probably the author of most of our uppercase FALSE, TRUE, and NULL docblocks, since that's what I've done in the past when there didn't seem to be a documented standard for it yet (or maybe I just was unaware). If @BWPanda is planning on fixing the coding standards as they are currently documented and implemented in phpcs in #6004, I'm on board with simply closing this issue. We'll proceed with following the coding standards as written, and fix existing docblocks that use FALSE, TRUE, and NULL to be all lowercase. Type-hinting if added in the future will also be lower case. Does that sit well with everyone? |
I think everyone is ok with that so I'll close this issue. |
Does the Code Standards need to be updated, or is it the codebase docblocks?
There are number of places in core where we've got
@return string|NULL
or@return array|FALSE
, for example. Yet, the current revision of the code standards state they should be lowercase:null
,false
,true
. Many of the uppercase examples were added as part of: #1937 and #2060 which were cleaning up code standards in core. This happened around the same time that the code standards was added, which was inherited from Drupal 7. Some things were updated in the code standards, but not the notes aboutnull
etc in the docblocks.I'm moving this discussion here from backdrop-ops/phpcs#5.
My quick and dirty search in core (PHP files only):
|null
- 21 results|NULL
- 52 results|false
- 9 results|FALSE
- 33 results|true
- 0 results|TRUE
- 1 resultI had figured it made some sense to use capitals since
NULL
,TRUE
,FALSE
are not like the other data types, they are the actual values. So perhaps it would be good to match the case with where it appears in the code? Whereasarray
,bool
,int
,string
are data types. While it's true they are case-insensitive, I figured that, since we've standardized to using all-caps in the code, that in the comments when we are explicitly saying what value is returned that we use the all-caps so as not to confuse it with a data type, and so that it matches the explanation below it. Here's an example from core/includes/ajax.inc:or core/includes/menu.inc:
The text was updated successfully, but these errors were encountered: