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
| 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
- #1815982: Plugin class names violate naming standard
- #1815988: UUID class names violate naming standard
- Cache Backends
- Configuration Storage Backends
- Database Queries and Query Interfaces
- Entity Storage and Field Items
- File Transfer Engines
- Key-Value Stores
- Queue Backends
- Misc (Mail/VariableLog, Archiver/Tar, Archiver/Zip)
- #1875996: Reconsider naming conventions for derivative classes
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | classes.txt | 69.89 KB | threewestwinds |
| #13 | classes.txt | 29.82 KB | threewestwinds |
| #10 | classes.txt | 28.41 KB | threewestwinds |
| #1 | classes.txt | 27.62 KB | jhodgdon |
Comments
Comment #1
jhodgdonI 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.
Comment #2
jhodgdonAs a reminder, this standard was adopted on #1507828: [policy, no patch] Revised standards for class naming within namespaces
Comment #3
jhodgdonAs this goes well beyond database classes, changing component.
Comment #4
pounard+1 for this issue
Comment #5
xjmDemoting 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.
Comment #6
pounardIt sounds wise.
Comment #7
threewestwinds commentedIf 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.
Comment #8
xjmAnd 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).
Comment #9
jhodgdonRE #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!
Comment #10
threewestwinds commentedThanks 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.
Comment #11
pounardI don't see what's wrong with UuidPecl, at least we don't have our file names yelling on us.
Comment #12
jhodgdonRE #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?
Comment #13
threewestwinds commentedDefinitely 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.
Comment #14
jhodgdonI 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?
Comment #15
threewestwinds commentedDIC 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.
Comment #16
jhodgdonSounds good! (meta-issue with sub-issues)
Comment #17
threewestwinds commentedI'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.
Comment #18
fubhy commentedYes, 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.
Comment #19
fubhy commentedChanging to task. It's not really a bug, or is it? :)
Comment #20
jhodgdonActually, a violation of our coding standards *is* a bug. :)
Comment #21
threewestwinds commentedAgreed 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.
Comment #22
jhodgdonThat does sound like a good idea. Let's go ahead and mark this "postponed" for now.
Comment #23
dozymoe commentedI 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().
Comment #24
jhodgdonAs 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.
Comment #25
fubhy commentedYes, I am increasingly in pain with this myself. :/ I think we should be able to fix that after feature freeze (Dec 1st).
Comment #26
threewestwinds commentedWith 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?
Comment #27
jenlamptonTagging this so that we can revisit with the markup cleanup :)
Comment #28
jenlamptonread the issue... wrong kind of "class" names. sorry kids :/ untagging.
Comment #29
jhodgdonRecent 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.
Comment #30
threewestwinds commentedI 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?
Comment #31
xjmWell, 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.
Comment #31.0
xjmAdded issue summary and change into [META].
Comment #32
xjmI added #1875996: Reconsider naming conventions for derivative classes to the summary. See also #1888702: Use configuration selection instead of derivatives for some blocks.
Comment #33
threewestwinds commentedThere 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.txtComment #34
tim.plunkettplugin_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.
Comment #35
jhodgdonIt is time to un-postpone this effort, since we're officially in "Clean Up The Code" phase now.
Comment #36
threewestwinds commentedI'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.
Comment #37
jhodgdonOh 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.
Comment #38
jhodgdonJust a note that the standards for class naming are probably going to be updated:
#2027221: [policy] Revisit class naming standards
Comment #38.0
jhodgdonUpdated issue summary.
Comment #39
mgiffordComment #40
manningpete commentedComment #46
frobShould this issue still be postponed? 8.1-5 has come and gone.
Comment #52
quietone commentedThere is an issue to re-evaluate the naming standard. Let's keep this postponed on that, #2027221: [policy] Revisit class naming standards
Comment #58
quietone commentedComment #59
quietone commented