We officially have access to php 5.4.x which means we can leverage traits. As @Crell mentions here: http://www.garfieldtech.com/blog/beyond-abstract abstract classes a likely unnecessary in favor of traits + interfaces. DBTNG is one of the hardest systems to follow in the IDE due to a.) it's architecture and b.) it's documentation. I've attempted to fix quite a bit of both these problems as they exist within the schema portion of dbtng as a first pass. I've introduced a SchemaInterface and moved all the methods in the abstract schema class into a DatabaseSchemaTrait. Hopefully this gets us started in introducing traits into D8.
Eclipse
Comment | File | Size | Author |
---|---|---|---|
#55 | 2206183-55.patch | 41.38 KB | lokapujya |
#38 | 2206183-38.patch | 41.53 KB | EclipseGc |
Comments
Comment #1
EclipseGc CreditAttribution: EclipseGc commentedwhoops
Eclipse
Comment #2
sunAny particular reason for why we need both abstract methods in the trait AND the same methods on an interface? The interface should be sufficient, no?
Comment #4
EclipseGc CreditAttribution: EclipseGc commented@sun,
I had the same reaction initially, but the trait really is an implementation of the interface and if I don't put abstract methods on it, then it could be used outside the interface's confines, which while exceptionally unlikely, is not outside the realm of possibility. Some of this is discussed here: http://www.garfieldtech.com/blog/beyond-abstract#comment-2398
I'm pretty new to this trait thing so... open to suggestions, but I tried to implement this as I thought was "right" from the perspective of the interface I introduced.
Eclipse
Comment #5
EclipseGc CreditAttribution: EclipseGc commentedSchemaTraits.patch queued for re-testing.
Comment #7
EclipseGc CreditAttribution: EclipseGc commentedMissed a testing file, let's see if this passes.
Eclipse
Comment #9
EclipseGc CreditAttribution: EclipseGc commentedFixed some tests and strings.
Eclipse
Comment #10
EclipseGc CreditAttribution: EclipseGc commentedDocumentation fixed based upon the evolving discussion in #2206175: [policy, no patch] Figure out how to document traits and trait methods and removed some unnecessary use statements in the trait.
Eclipse
Comment #11
EclipseGc CreditAttribution: EclipseGc commentedoops
Comment #12
Damien Tournoud CreditAttribution: Damien Tournoud commentedColor me not convinced here. Having the interface is a good thing, but your trait here is really an abstract base class... so there is no real advantage in having it as a trait, it just makes things a little bit weirder with no gain.
Traits are for code reuse of relatively self-enclosed behaviors. Here there is no such thing, so let's keep the abstract base class.
Interface yes, trait (as is), no.
Comment #13
tim.plunkettTraits are nice when you don't want to squat the only opportunity to use
extends
that a class can have.But this is clearly a case where we actually want a base class:
Drupal\Core\Database\Driver\mysql\Schema extends Drupal\Core\Database\Schema
Comment #14
msonnabaum CreditAttribution: msonnabaum commented100% agree with #12.
Comment #15
EclipseGc CreditAttribution: EclipseGc commentedAs I said to msonnabaum earlier today, I don't really feel like this is a fight either way. I prefer our system to be more flexible, but if the world is against this as an approach, that's fine too. Still Crell makes the point that abstract base classes are largely vestigial as of 5.4.x. If we collectively don't agree, alright by me, but this seems like something we should discuss more.
FWIW, I interpreted abstract class's new place in the world identically to Crell.
I'll roll another patch moving this back to an abstract tomorrow and we can discuss further from there.
Eclipse
Comment #16
Damien Tournoud CreditAttribution: Damien Tournoud commented@EclipseGc: it's a question of code organization. ABCs can be considered as vestigial only if you organize your code around small, relatively self contained object behaviors (emphasis on small and self-contained). Without further refactoring we don't do such a thing here, the
abstract class Schema
is a big mix of a lot of different stuff all closely tied together.If broken down, many of those would be good fit as a trait (the clearest one being a concrete implementation of PlaceHolderInterface), but until broken down it's better to keep the whole thing as an ABC.
Comment #17
Crell CreditAttribution: Crell commentedIn the interest of progress I'm OK with backing off on the trait here and circling back around later after further refactoring (should any happen in D8), which I think we all agree is long-overdue for Schema API.
Damien is correct that placeholderinterface is a good target for traitification.
Comment #18
jhodgdonThe documentation in this patch is not going to work.
The main doc block for this Trait starts with
Defining a @defgroup needs to be separate from the Trait's doc block.
Also, there's an issue about defining standards for how to document traits that may be of interest:
#2206175: [policy, no patch] Figure out how to document traits and trait methods
Comment #19
EclipseGc CreditAttribution: EclipseGc commentedOk, discussed this with Crell a little bit, and have opted to just trait-ify the Placeholder stuff. Otherwise, I've moved this back to an abstract base class but it has an interface now. I used git diff -M so it's pretty easy to read. I did however move a few methods around to be better groups which made for some patch weirdness. All the Schema subclasses (except tests) were using the class as DatabaseSchema, so I renamed the class to DatabaseSchema. I think it reads pretty easily. I also added the trait in the 2 other classes that were implementing PlaceholderInterface as they had the identical code to what was in my trait. There are tests that also implement the interface but they JUST throw exceptions, so the scope of this was super narrow. I also updated the docs for most of the files I touched, but especially in the SchemaInterface I tried to nail down all the returns as many of those were missing.
Hopefully this seems better to everyone in terms of using a trait and generally cleaning up some stuff in DBTNG.
Also, addressing jhodgdon's point, I moved back to an abstract base class, so I _THINK_ that's no longer an issue.
Eclipse
Comment #20
EclipseGc CreditAttribution: EclipseGc commentedbah cross posts :-(
Eclipse
Comment #21
EclipseGc CreditAttribution: EclipseGc commentedBased on feedback in irc, encapsulated the uniqueIdentifier() method within the trait.
Eclipse
Comment #22
EclipseGc CreditAttribution: EclipseGc commentedfixed a comment I missed in the trait, otherwise the code's identical to 21, shouldn't need a retest.
Eclipse
Comment #24
EclipseGc CreditAttribution: EclipseGc commentedI asked Randy Fay to cancel that last test. Here's an interdiff.
Eclipse
Comment #25
Crell CreditAttribution: Crell commentedIt looks like you moved where these methods are in the class (probably an artifact of earlier versions of the patch), which makes the patch larger and harder to review. It took me a while to figure out what happened to all of this code. :-)
I don't know that there's anything to do here, but I'm mentioning it in case a later reroll could be smaller/easier to read.
I'm not sure if the interface should extend, or if the class should just implement both. Open to thoughts here.
Comment #26
EclipseGc CreditAttribution: EclipseGc commentedYeah, I mentioned that I moved a couple methods around to re-organize them in a fashion I felt was easier to read. I'm cool either way on the extend/implements for PlaceholderInterface, just need a decision one way or the other.
Eclipse
Comment #27
jhodgdonI took a look at the documentation changes in this patch. There are a few issues:
a) class DatabaseSchema
A member variable needs to have a one-line description as well as @var. This patch replaces the description with @var instead of adding to the description.
b) DatabaseSchema::getPrefixInfo()
This makes zero sense to me. It says it's the name of the table and then says something about keys and prefixes -- what does this mean? What is a prefix and what is a key? This also applies to several methods in SchemaInterface with 'prefix' in their names. As far as I can see, prefixes are never explained and I have no idea what it is from reading this documentation.
c)
A Trait still needs to have a one-line description of what it is for. @see just gives you a See Also, not documentation.
d) (minor) In the new SchemaInterface, the method docs should all start with 3rd-person verbs, like "Creates" instead of "Create". Some currently do, and some do not.
These are relatively minor and/or preexisting conditions except (a) and (c), which really needs to be fixed for sure (our Documentation Gate says that everything at least needs one-line documentation).
Comment #28
EclipseGc CreditAttribution: EclipseGc commentedYeah, that connection var has no docs in HEAD currently, but I'll put a description on it. I did this much to make sure IDEs would parse through it properly. b.) is only visible because I physically relocated some of the existing docs, so yeah we should probably address that in a follow up, and c.) is something I knew I needed to do. Sorry I've not yet done it. I'll get a/c squared away as soon as Crell gives me an answer on #26.
Eclipse
Comment #29
EclipseGc CreditAttribution: EclipseGc commentedDiscussed with Crell the PlaceholderInterface question he posed above. My basic question was "do you want to have to check the PlaceholderInterface for various SchemaInterface classes, to which he answered "no" and we decided SchemaInterface should indeed extend PlaceholderInterface.
This patch then only changes the documentation issues A & C that jhodgdon outlined in 27. Hopefully this takes this patch the rest of the way home.
Eclipse
Comment #30
EclipseGc CreditAttribution: EclipseGc commentedmissed the status...
Eclipse
Comment #31
Crell CreditAttribution: Crell commentedI think any other missing documentation can/should be handled by #2192185: Improve DB API code documentation. Thanks, Kris!
Comment #32
msonnabaum CreditAttribution: msonnabaum commentedLooks much better to me.
Comment #33
webchickLooks like we lack a change record draft for this. At least the "use" statement in implementing classes needs to change, not sure how much else of this is developer-facing.
Comment #34
EclipseGc CreditAttribution: EclipseGc commentedWrote the change record.
Eclipse
Comment #35
Crell CreditAttribution: Crell commentedMade a slight language tweak to the change notice. Back to RTBC.
Comment #37
EclipseGc CreditAttribution: EclipseGc commentedrerolled
Eclipse
Comment #38
EclipseGc CreditAttribution: EclipseGc commentedadded back in the docs changes that caused the original breakage of this patch in #29. If 37 passes 38 should pass.
Eclipse
Comment #39
Crell CreditAttribution: Crell commentedBot can object.
Comment #41
ianthomas_ukThe failure on #37 looks like the testbot just ran out of diskspace, so nothing to worry about for this issue.
Comment #42
EclipseGc CreditAttribution: EclipseGc commentedComment #44
Crell CreditAttribution: Crell commented38: 2206183-38.patch queued for re-testing.
Comment #45
Crell CreditAttribution: Crell commentedTestbot burped. Can we get this committed before it burps again?
Comment #46
EclipseGc CreditAttribution: EclipseGc commentedSeconding that request. The last re-roll was comment related.
Eclipse
Comment #48
EclipseGc CreditAttribution: EclipseGc commented38: 2206183-38.patch queued for re-testing.
Comment #49
EclipseGc CreditAttribution: EclipseGc commenteddunno what's up with testbot, but this still passes test.
Eclipse
Comment #50
jibranmore then 80 chars.
Comment #52
Rajendar Reddy CreditAttribution: Rajendar Reddy commentedUpdating patch with reroll. Please review.
Comment #54
Crell CreditAttribution: Crell commentedComment #55
lokapujyaNot sure this will work, but it should apply.
Comment #57
Crell CreditAttribution: Crell commentedSo if we reroll this again and make it work, when's a good time for it so that it doesn't sit here and get stale again? That's one of the most demoralizing things in the issue queue, especially for something that's just moving code around to make it cleaner...
Comment #58
jhedstromIs this still under consideration for 8.0.x?