So, we got off the island, and we're using libraries.
However, the entire outside world is using PSR-2, which means camelCase variables. Which means interfaces with method signatures that use camelCase variables.
D8 still uses snake_case for things that aren't class properties, for some odd inconsistent reason.
So, if a class implements one external interface, and one core interface, you get some methods with snake_case arguments, and some with camelCase arguments.
Drupal core has this problem when integrating with Symfony, but the number of classes with the problem is small and less visible.
Commerce however, has decided to move core logic and interfaces to external libraries, and our every entity implements a foreign interface.
So, right now Commerce method arguments are 90% camelCase, and 10% snake_case (constructors and form() methods, basically).
Based on this, and following positive community feedback, I'm about to create a "Commerce uses camelCase everywhere internally" rule, and break Drupal coding standards for the entire 2.x cycle.
larowlan wanted me to document my experience, so here it is. I know changing to camelCase in the D8 cycle is extremely unlikely, our choices have just left us in a painful position.
Comments
Comment #1
bojanz commentedComment #2
larowlanRealise this is off the table for 8.x, into 9.x territory.
But we have code-generators etc and if we decided to move in this direction, we could do so in one jump with things like pharborist. Maybe when we decide to open the 9.x branch for development?
Comment #3
bojanz commentedComment #4
tim.plunkettIs Commerce also going to use 4 spaces for indenting?
Or opening { on new lines?
Or any of the other asinine rules proscribed by PSR-2?
I don't see the point. PSR-1 is enough.
Comment #5
bojanz commented@tim.plunkett
No, just the minimum required to stay internally consistent. It's all about the variables, as imposed by the interfaces.
Hence the title of the issue being about snake_case, not full PSR-2.
Comment #6
tim.plunkettGood point, the only part of PSR-2 that would affect runtime PHP code is the variable names.
Fair enough.
Comment #7
xanoInterfaces impose a number of parameters, and their types and default values. Parameter names can be changed in implementations, however. Example.
Comment #8
tim.plunkettOh duh, we do that already in a couple places. Whoops, thanks.
Won't fix?
Comment #9
bojanz commentedSure, you can change the argument name. But that makes every inherited docblock now wrong, which would be a bit of a WTF to people reading the docs.
(Perhaps redeclare the docs?)
The feedback on #drupal-contribute was that breaking Drupal's coding standard was the less weird option here.
Comment #10
alexpottIf we are designing code to be interoperable then going with camel case makes sense. And yep we probably have to move to camel case properties in d9.
Comment #11
dawehnerIt is a hard topic.
If we are honest, we should have went with the PSR-2 code style. You know, code style is something your brain accepts and get used to it.
The only problem is, if you have to switch between different styles.
You though could also ask various vendors (STORM, phpdoc) to just care about the order of parameters, not the names.
Comment #12
jhodgdonThis looks like a project-wide coding standards discussion, not a Core-specific coding standards discussion. So it should (sigh) be in the (semi-defunct at least) Technical Working Group issue queue.
Comment #13
David_Rothstein commentedSomething that came up in #2474561: Coding standard: inconsistent requirement that arguments to setters methods should be $lower_case when private variable and setter methods are camelCase() (a closely related issue) is that currently there is no coding standard for this one way or another. There is sort of a de facto standard that method arguments use snake case (to match function arguments), but it's actually not written in the official coding standards at all, as far as I can tell. It would be good to clarify that either way.
Comment #14
tizzo commentedMoving this issue to the Coding Standards queue per the new workflow defined in #2428153: Create and document a process for updating coding standards.
Comment #15
gappleI think this can be marked as a duplicate of #2648050: [policy, no patch] Stop disallowing camelCase for local variables / parameters, which has been marked RTBC
Comment #16
pfrenssenActually PSR-2 doesn't say anything about requiring camel case for variables or properties :)
It even gives examples that mix both camel case and snake case in a single variable name, which is kind of ridiculous:
PSR-2 builds on top of PSR-1 which specifically allows projects to choose their own style: