To establish agreed ground rules, I'd like to get some clarification of how we deal with "deprecated" APIs.
There are a fair number of procedural APIs that are labelled like this (in this case, for entity_create):
Deprecated
in Drupal 8.0.x, will be removed before Drupal 9.0.0. Use The method overriding Entity::create() for the entity type, e.g. \Drupal\node\Entity\Node::create() if the entity type is known. If the entity type is variable, use the entity storage's create() method to construct a new entity:
While entity_create() is marked this way, right now, it is also used in core more than 450 times.
9.0.0 is not close; I'd guess it's as many as 5 years off.
In the past, we've looked at the code in Core as the model for Examples. Right now, Core uses a lot of these APIs heavily, and will continue doing so for years.
While I think that getting rid of deprecated APIs is worth doing, I"m skeptical it's worth spending a lot of time on it now.
What do people think about this?
Comments
Comment #2
mile23Doesn't matter whether core uses deprecated functions. :-) Check out the @deprecated issue tag for core. It's a big task.
Examples is a documentation project where we demonstrate best practices, including not using deprecated APIs.
For issues like this: #2581559: Port Field Permission Example to Drupal 8 we have a choice: We can commit a module with deprecated code and then follow-up, or we can say fix the deprecations and then we can commit it. Either way, we fix the deprecations. :-)
Comment #3
martin107 commentedIt is a beautiful thing - that we have say 5 years notice to move away from deprecated functions.
Can I suggest there are 2 cases where we must act well before the inevitable mad rush 4.5 years from now.
1) scaffolding
for example drupal generate:authentication:provider
2) When we are trying to teach people best practise ... so here in the examples module.
As for scaffolding
https://github.com/hechoendrupal/DrupalConsole/issues/1875
https://github.com/hechoendrupal/DrupalConsole/issues/1874
I have made a start.... if anyone can think of any other generate command I have missed please let me know...
As for the examples module...
I understand but I want to do it bit by bit in small isolated issues...over many months if anyone want to create an issue I will jump on them and help out with patches and review.
anyone can feel free to nudge me as they create a new issue... I hope to make a start with issue of my own as the weekend develops.
Comment #4
Torenware commentedTrue. But we are also a major source of sample code to help people get their work done. We are a essentially at teaching and training project. The "best practices" and "learn how to code this efficiently" goals are not necessarily at odds, but neither are they the same.
We do need to fix the deprecated calls. The question is: when and how. Let's look a bit more at the Field Permission Example. The
entity_*()family of functions are deprecated, but at present, you'll find very little in Core currently uses anything else (try it -- I checked). In spite of these functions getting deprecated very early in the Drupal 8 dev process -- back in 2013. You won't find a lot of code in Core done in the style of my latest FPE patch. The closest I found was in the implementations of the old procedural functions themselves.So why are they still so heavily used in Core?
Part of it is how much more verbose the "recommended API" is. The D7 entity methods are, by in large, more compact than the OO methods that replace them. So even after the old procedural function were deprecated -- as many as two years after -- people working on Core kept on using them. This isn't a problem with OO code per se. But I do think it's a problem with some of our current OO APIs. In places, we really do need some convenience functions in the new APIs that are currently missing. In the meantime, some of the procedural functions are considerably more concise, and therefore, it's easier to write correct (as in "it works correctly") code using them. So even in Core, the functions keep popping up. It's still easier to write code that looks like what it means, and actually does what it says, if you use some of the convenience functions. So people keep doing it.
Because some of the new style coding is a PITA, I strongly suspect that some of the APIs will get extended a bit for the sake of better developer experience. But that will happen because people start changing Core, and not because we or anyone else tries to implement the deprecation strategy before it actually gets further along in Core.
Another part of the reason is how much of our test code still uses SimpleTest, which does not mix well with some of our newer OO code. For example, SimpleTest test classes are not containers; in fact, due to how they get called, they actually can't be containers. You can clean up some of this kind of code, but there's a conflict between coding clearly (i.e., writing code that is at least somewhat self-documenting) and coding "correctly", as we've been defining it. For the FPE, I needed to look at the test code used in Core, which is very old-style. I could use the existing KernelTest based code as a model (bad?) or I could write an entirely new base class for the FPE. Which might differ more than a little from whatever PHPUnit based test will ultimately replace the current base class, some time before we get to 9.0. But in some cases, changing to PHPUnit tests before Core does is very tough, very low level coding.
Take the Rules module for D8 as an example. The code for Rules D8 has gone pretty far in this direction. I've done a fair bit with the Rules people. fago and klausi write very cutting edge Drupal code, and excellent code it is. But it's not a fast process. Perhaps we will have a usable very of Rules in time for DrupalCon New Orleans. But we may well not. What klausi did to make that happen in Rules was hard. I encourage anybody to ready his base classes for Rules phpunit tests. There's very little like it in Core, and it works nicely. But even for klausi, some of that code didn't quite do what he thought it did, as we discovered when we found that the new code didn't behave like the older procedural style code. Which did what we thought the code should do. Which is a risk you take when you diverge from what typical Core code looks like.
This is a case where, like the French say, the Best is the Enemy of the Good. Part of what's keeping back D8 adoption is a lack of good sample code. Part of the Example project's goal is to be just such a source of good sample code. But since so much of our code is churning in patches, and not getting checked in, it's not very available sample code. For a lot of Drupal coding work, Core is still the only sample code that people can find. And it's not necessarily as usable as we might like.
I think that there's a balancing act between suppling the Drupal community with good code to work from as soon as we can, vs. supply the community with the "right" code, whenever we can finish it. I'd argue that we may want to rebalance how we're approaching that.
Comment #5
mile23Why would they be? The container for tests is
$this->container. The test classes are run by the test runner, which has its own kernel. This kernel is distinct from the kernel under test.This is not a case of the best being the enemy of the good, but the best practice being the enemy of the global function. I do hear what you're saying, though. I keep hoping things like #2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits will land and I can go ahead and have a guilt-free commit.
Also, I'm staring down the barrel of this fact, trying to figure out what to do: If you look at any testbot run, you'll see that we are currently testing against Drupal 8.1.x, even though the project is written against 8.0.x. There is nothing anyone can do, apparently. #2663018: Useful core branch defaults for contrib CI
Comment #6
mile23So we have CI running against Drupal core stable, because the testbot lets us do that now.
#2605664: [Needs change record updates] Align TestDiscovery and bootstrap.php's non-permissive loading of PSR-4 namespaces for traits made it in so our PHPUnit tests are much happier.
Also, more and more of the deprecated code in core will @trigger_error() and fail tests, as well, after #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases
Comment #7
mile23Made an issue to keep track of all the stuff we need to do immediately when 8.6.0 is released, but not before: #2992455: [meta] 8.7.0 deprecation changes
Comment #8
andypostRight now some clean-up happened in #3072416: [Meta] Drupal 9 Deprecated Code Report
The idea was to clean-up all 8.0 deprecated remains and do initial clean-up with drupal-check
At the end module should be able to enable this kind of testing #3014492: Adopt Gitlab CI and fix CS violations detected
The solution to versioning could remain - keep all in head, otoh examples could create separate branches according core
Not sure that more then dev releases needed
Comment #9
kristen polPer a Slack discussion with Gábor Hojtsy regarding usage of D9 tags (Drupal 9, Drupal 9 compatibility, Drupal 9 readiness, etc.), "Drupal 9 compatibility" should be used for contributed projects that need updating and "Drupal 9" was the old tag for D8 issues before the D9 branch was ready. Doing tag cleanup here based on that discussion.
Comment #10
jungleI guess this is outdated. Please reopen if necessary.