Postponed on #2027221: [policy] Revisit class naming standards

Problem/Motivation

Many core class names violate our naming standards as laid out in http://drupal.org/node/608152. Classes and interfaces should have names that stand alone to tell what they do without having to refer to the namespace, read well, and are as short as possible without losing functionality information or leading to ambiguity

Fixing these class names to be more self-explanatory will help code be self-documenting and ease the introduction of new contributors.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because most fixed issues tagged coding standards are marked as tasks
Issue priority Not critical

Proposed resolution

Change class names to conform with already adopted standard.

Remaining tasks

User interface changes

None

API changes

Renaming classes in Core is likely to require large updates to existing patches and contributed modules. If we intend to enforce the naming standard, it should be done as soon as possible.

Original report by jhodgon

At some point, and I don't know exactly when, the class names for our database classes were changed from e.g. MergeQuery to Merge. I cannot even find a change notice about it (I searched for MergeQuery and got nothing), so I am unable to locate the issue where this was done and/or discussed.

However, our coding standards state:
http://drupal.org/node/608152 point 10 in Naming:

Classes and interfaces should have names that stand alone to tell what they do without having to refer to the namespace, read well, and are as short as possible without losing functionality information or leading to ambiguity

This means that MergeQuery -> Merge is in clear violation of that standard. We should change them back.

Comments

jhodgdon’s picture

Issue tags: +Coding standards
StatusFileSize
new27.62 KB

I just rebuilt my API site for Drupal 8 (api.drupal.org is out of date for reasons having to do with memory problems on the server, sorry!) and scanned the class list... it seems like this might be a wider problem. I'm attaching a list of all 341 current class/interface names -- this excludes tests (which have an exception in the rules) and vendor classes (which don't conform to our standards). Maybe we should change some others?

Note: the attachment is a CSV file, so if you save it to your computer and change the extension, you should be able to open it in OpenOffice etc. as a spreadsheet with nice columns and stuff.

jhodgdon’s picture

Title: New class names for database classes violate our coding standards blatantly » Many core class names violate our naming standards blatantly
jhodgdon’s picture

Component: database system » other

As this goes well beyond database classes, changing component.

pounard’s picture

+1 for this issue

xjm’s picture

Priority: Major » Normal
Issue tags: +Novice

Demoting per IRC conversation. Doing an inventory of these would be good, as would git-blaming the names to see what justifications there are for the changes.

pounard’s picture

It sounds wise.

threewestwinds’s picture

If I understand the new naming convention properly, there are potentially quite a large number of changes. Some of the easier examples:
Tar -> TarArchiver
Zip -> ZipArchiver

Com -> UuidCom
Pecl -> UuidPecl
Php -> UuidPhp

I'm a little less sure about the database names - I would think "Delete" falls under the "too ambiguous" clause of the naming convention. Is this change correct?

Database/Query/Delete -> DeleteQuery
Database/Driver/mysql/Delete -> DeleteQuery
(etc. for other drivers)

If I'm on the right track here, I'll be happy to go through and create a list based on jhodgdon's compiled class/interface names.

xjm’s picture

Com -> UuidCom
Pecl -> UuidPecl
Php -> UuidPhp

And actually it should be UUID and PHP and etc. See http://drupal.org/node/608152 #3 and #1627350: Patch for: Case of acronyms in class names (SomethingXSSClassName versus SomethingXssClassName).

jhodgdon’s picture

RE #7 - yes, you are definitely on the right track! With the caveats in #8, I agree with all of your suggestions... (I think so anyway -- I haven't confirmed that DatabaseDriveer/mysql/Delete is actually a delete query class, but I assume it would be -- if so, good naming. :) ) So yes, go for it! Thanks!

threewestwinds’s picture

StatusFileSize
new28.41 KB

Thanks for the pointer on capitalizing the acronyms. UUID in particular is tricky though, since all of its backends are other acronyms - UUIDPHP and UUIDPECL are not terribly readable.

I see three options:
UUIDPHP, UUIDPECL <- In keeping with the standard, but I find it hard to parse visually.
UuidPHP, UuidPECL <- Make an exception to the standard
UUIDBackendPHP <- Use an extra word in between (they are backends, but there's likely a better term).

With that said, here's a list of the proposed changes. I aimed to be conservative. Transaction, Statement and Schema in particular I left as is - while not database-only terms, they have several derived class names (such as StatementEmpty, StatementPrefetch), so changing them would result in some unnecessarily long class names elsewhere.

pounard’s picture

I don't see what's wrong with UuidPecl, at least we don't have our file names yelling on us.

jhodgdon’s picture

RE #11 - that standard has already been adopted, sorry. See links in #8.

RE #10 - Thanks for starting on this! I think your choices in there look reasonable. I don't think we have a complete list yet though... here are some notes and thoughts:

a) The following namespaces I think need to have some/all their classes have more specific names (including the namespace):
- Plugin
- Annotation
- Cache [DatabaseBackend needs to have Cache in name, for instance!]
- Config [DatabaseStorage needs to have Config in name]
- Database/Statement
- DependencyInjection/ContainerBuilder.php
- KeyValueStore [as usual, there's a class called DatabaseStorage, and some others that are ambiguous]
... You get the idea -- that's as far as I got.

b) I *do* like what you did with the UUID class names.

c) What is EntityNG? I think this name just needs to have "NG" written out (it is not, at least to me, a familiar acronym).

d) Given that the word "Field" can refer to a database field or an entity field, any class names with Field in them need to be obvious which is which. Also, I don't know who decided the individual field types should be called *Item, but to me that isn't clear and they should have Field in the name instead?

threewestwinds’s picture

StatusFileSize
new29.82 KB

Definitely not a full list, agreed. Here's a more complete one, with some comments below.

NG appears to stand for "New Getter" - it is a set of temporary classes introduced in #1696640: Implement API to unify entity properties and fields. They will be removed before release, so I'm not worried about spelling out the abreviation too much.

Agreed with D) - FieldItem is better than just Item.

In the Core/Entity namespace, does "Controller" add information to the class names? For example, as far as I can tell, EntityForm is just as explicit about what the class does as EntityFormController.

Plugin -> PluginAnnotation. I was unfamiliar with "Annotations" in a programming context, so I didn't touch the names there. After looking over the code, I think I understand them a bit now.

DatabaseBackend -> DatabaseCache. As per the standard, "CacheBackend" doesn't provide any more information than "Cache" does alone.

MapperExceptionInterface, InvalidDecoratedMethod - These classes are unused. I will file a separate issue to remove them.

ContainerBuilder -> DICBuilder, RegisterKernelListenersPass -> DICKernelListenersPass - I think that DIC is a standard abreviation in use in the issue queue?

I don't understand the systems around EntityTranslation and EntityWrapper well enough to intelligently rename them. My best guess is that they should be EntityTranslationField and EntityWrapperFieldItem, but those are only guesses.

I believe that Field should be in the Field/ namespace, rather than Field/Type/, since it implements FieldInterface rather than FieldItemInterface. That's something for a seperate issue, if true.

Widget is hopefully unambiguous enough that it doesn't need to be changed to FieldWidget.

jhodgdon’s picture

I haven't looked through the new list yet, but a few notes:
- "Controller" is a specific software development term, so yes I think that it does add something to a class name.
- "Backend" is a term that the Cache documentation uses, so yes I think it does add something to a class name.
- "DIC" -- I have zero idea what it stands for, and if I don't have a clue, probably an average person browsing classes doesn't either. So unlike HTML and FTP and stuff like that, I would say it probably needs to be spelled out?

threewestwinds’s picture

DIC stands for Dependency Injection Container. If the abbreviation isn't clear, I'm not sure how to name those classes concisely. InjectionContainerListenersPass is pretty unwieldy. Those two classes are very much internal - I can't think of a reason for contrib to extend or even reference them at all.

On a practical note, I'm starting to wonder how we'd handle this renaming as a patch. While in review/testing, it would have to be re-rolled quite often to chase head, and once it landed, every patch in the queue would have to be redone to accomidate it. And especially for some of the more confusing names, getting buy-in from people involved in that system will take time.

Basically, I'm not sure compiling a list of every change that should be made in one place is helpful. It might be better to open a separate issue for each component that needs to be updated - smaller patches and a smaller section of the community that needs to be involved will make actually implementing this change feasible.

I'll edit the issue summary and change this into a [meta] issue later.

jhodgdon’s picture

Sounds good! (meta-issue with sub-issues)

threewestwinds’s picture

Title: Many core class names violate our naming standards blatantly » [META] Many core class names violate naming standards

I've started to create sub issues, one for each component affected. So far:
#1815982: Plugin class names violate naming standard
#1815988: UUID class names violate naming standard

The issue summary is also updated accordingly. More to come later. Anyone help pointing to existing issues I may have missed or creating the rest of the issues mentioned in the Summary would be very welcome.

fubhy’s picture

If we intend to enforce the naming standard, it should be done as soon as possible.

Yes, but let's at least wait until after feature freeze before committing any of this. The pace at which we have been moving lately caused so many re-rolls already. A big change like this which would affect many files is going to make that even worse.

Anyways. This is really important and should indeed happen as soon as possible. But lets wait until after 1st of December.

fubhy’s picture

Category: bug » task

Changing to task. It's not really a bug, or is it? :)

jhodgdon’s picture

Category: task » bug

Actually, a violation of our coding standards *is* a bug. :)

threewestwinds’s picture

Agreed on waiting until after feature freeze. I saw it mentioned in another issue around coding standards, which is why I haven't moved any further on this.

jhodgdon’s picture

Status: Active » Postponed

That does sound like a good idea. Let's go ahead and mark this "postponed" for now.

dozymoe’s picture

I think Controller stands for a class that served a page request @_@ (not sure). In Drupal term that might be the page callback of hook_menu().

jhodgdon’s picture

As a note, when we re-open this issue, there are a LOT more classes in Core now than there were when the lists above were generated (e.g., Views). So we need to start over by generating a list of all the classes in Core again, and looking at which ones need fixing.

fubhy’s picture

Yes, I am increasingly in pain with this myself. :/ I think we should be able to fix that after feature freeze (Dec 1st).

threewestwinds’s picture

With the introduction of the new Feature Completion phase, I think we should leave this issue postponed until February 18. New features are still in progress, and I think it would still be counter-productive to force rerolls and confusion by changing core class names under their feet.

Differing opinions?

jenlampton’s picture

Issue tags: +markup, +Twig, +theme system cleanup

Tagging this so that we can revisit with the markup cleanup :)

jenlampton’s picture

Issue tags: -markup, -Twig, -theme system cleanup

read the issue... wrong kind of "class" names. sorry kids :/ untagging.

jhodgdon’s picture

Recent issue that is probably a duplicate of this one or a sub-issue:
#1875996: Reconsider naming conventions for derivative classes

I wonder if it is also time to un-postpone this issue? Not sure what the schedule is for code cleanups.

threewestwinds’s picture

I had in my mind Feb 18th - the end of the "feature completion phase" - in mind for reopening this. On that day, we should have a 99% complete list of the classes that will be in 8.0 and can tackle them all at once, instead of having to keep updating the list as more features make it in.

It would certainly be possible to re-open now if someone wants to start work - I'll review any progress someone else makes, but don't want to start it myself until feature freeze.

Would it be correct to mark this meta-issue as Major when un-postponed, while leaving each issue it references Normal?

xjm’s picture

On that day, we should have a 99% complete list of the classes that will be in 8.0 and can tackle them all at once, instead of having to keep updating the list as more features make it in.

Well, I wouldn't go that far; there will still be refactoring and other tasks during feature freeze. :) However, I do agree we should wait until after Feb. 18.

xjm’s picture

Issue summary: View changes

Added issue summary and change into [META].

xjm’s picture

threewestwinds’s picture

StatusFileSize
new69.89 KB

There are currently 880 classes in core that don't have Test in the name - just a few more than the 341 we had back in October. 121 of these are from Views.

I also noticed the file and class names involving "plugin_test" and similar - it seems to go against the convention used in other modules. "_test" is used ~100 times, while Test is used ~800 in filenames.

Documenting this here so it doesn't get lost in my bash history - this list was generated from inside the core directory using the command:
find modules/ lib/ -name '*.php' | xargs grep -o "^class [_a-Z]*" | grep -v "Test" >> classes.txt

tim.plunkett’s picture

plugin_test is a module, and that's our standard for namespaces. In fact, stuff like "argument_validator" is also in the namespace, not the class name, and isn't subject to this.
We're just evaluating the class name.

jhodgdon’s picture

Status: Postponed » Active

It is time to un-postpone this effort, since we're officially in "Clean Up The Code" phase now.

threewestwinds’s picture

I've submitted a patch for #1815988: UUID class names violate naming standard - once that's reviewed and I know I'm on the right track, I'll create a few more for other subsystems.

@tim.plunket - Thank you, that is good to know. It would be issue-creep here even were it correct to change - I just noted it as something odd I'd seen while looking through the list of class names - and their namespaces, in order to figure out what ambiguous names should become.

jhodgdon’s picture

Oh gracious. It looks like we'd better decide on
#1627350: Patch for: Case of acronyms in class names (SomethingXSSClassName versus SomethingXssClassName)
before we go too far on this issue. Sigh.

jhodgdon’s picture

Just a note that the standards for class naming are probably going to be updated:
#2027221: [policy] Revisit class naming standards

jhodgdon’s picture

Issue summary: View changes

Updated issue summary.

mgifford’s picture

manningpete’s picture

Version: 8.0.x-dev » 8.1.x-dev
Category: Bug report » Task
Issue summary: View changes
Status: Active » Postponed
Issue tags: -Novice
  • Changed issue summary to add Beta phase evaluation.
  • While noting in comment #20 that jhodgdon says violation of coding standards is a bug, changed Category from bug to task after checking https://www.drupal.org/core/issue-category. Coding standards are not listed under either Bug or Task on that page, but a review of closed issues tagged "coding standards" showed the vast majority of such issues have been tagged as tasks, not bugs.
  • Postponed issue to 8.1.x-dev per https://www.drupal.org/contributor-tasks/update-allowed-beta
  • Removed Novice tag

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

frob’s picture

Should this issue still be postponed? 8.1-5 has come and gone.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

quietone’s picture

Issue summary: View changes

There is an issue to re-evaluate the naming standard. Let's keep this postponed on that, #2027221: [policy] Revisit class naming standards

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

quietone’s picture

Title: [META] Many core class names violate naming standards » [meta] Many core class names violate naming standards
Parent issue: #2571965: [meta] Fix PHP coding standards in core, stage 1 » #3553320: [meta] Fix PHP coding standards in core, stage 2

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.