Well, I suppose I could have said "aging" or "legacy" code base, but that doesn't capture my point, which starts with:
As an Oracle Database developer, though, it is not unreasonable to expect that my code will be in production for years, perhaps decades.
Now, that's persistent code. And why is that?
Now, that's persistent code. And why is that?
Because, well, DATABASE.
The database is the repository for your enterprise. Certainly it contains the data, and if you fully leverage the database properly, it will also contain your business logic.
And while it is not all that painfully disruptive to rewrite your UI code, it can be business-threatening to do any of the following:
- Switch your database technology
- Upgrade your database software too quickly
- Rewrite your business logic in a new scripting language
So your database - data and associated code - tends to be the most stable layer in your stack, with upgrades applied with great care, and code maintained for many years.
And "maintained" could mean:
- True legacy mode: no further enhancements, critical bug fixes only. This will always be true for at least a part of your code base, and I will not address it further in this post.
- Actively used and enhanced: this is where the action is. Sure, lots of the code has been around for years, and will continue to be. Most of it works great and doesn't need to be touched. But then there are enhancements, bug fixes, new features.
Oh, and, inevitably, deprecation. Which is the topic of this blog post.
Many things happen to code that lasts a long, and one of them is that we come up with better ways to do things. The "better" part could be a better name for a subprogram, a seriously modified parameter list, or an entirely new implementation.
And, of course, what you'd really like to do is immediately get rid of the "old stuff" and make sure everyone's program units, across the entire application, use only the cool, new stuff.
Sadly, that's not always possible. Sure you can send out an email:
Hey, folks, listen up! Don't use pkg_a.proc_b anymore. We've got a much better version in pkg_c.proc_d.But there's no guarantee that anyone (or, more to the point: everyone) will switch over to the new iteration. And since a published, in-use API is a sort of contract you signed with users, you can't just force them to change (usually).
So instead, the old stuff sticks around and might even get used again by a careless developer - even if you add a comment like:
PACKAGE pkg_a AUTHID DEFINER IS /* DON'T USE THIS! Use pkg_c.proc_d instead! */ PROCEDURE proc_b;
Wouldn't it be nice if there was a way to document deprecated functionally, so that when your code is compiled, you would be notified (and could even have it flagged as a compile error) that you are using out-of-date stuff?
Yes, that sure would be lovely.
[Pretend you are now listing to a Drum Roll....]
Welcome to PL/SQL 12.2 and the DEPRECATED pragma.
You want to notify developers that proc_b is out of date and proc_d should be used instead?
This is now what you do:
PACKAGE pkg_a AUTHID DEFINER IS PROCEDURE proc_b; PRAGMA DEPRECATE (proc_b, 'pkg_a.proc_b deprecated. Use pkg_c.proc_d instead.');
Looks really similar to the comment version, doesn't it? So what, then, does this pragma do for you? Not much, if that's all you do.
But let's suppose that you've decided your team should "step it up" in terms of code quality and overall professionalism.
As a part of that initiative, you are going to take advantage of PL/SQL's compile-time warnings. You go into SQL Developer's preferences, type "compile" in the search field, and find this:
Yep, as suspected, you are not currently utilizing compile-time warnings. So let's start by enabling all of them:
The compiler is simply notifying me that proc_b has been marked as deprecated. That's fine. But what happens when I try to use this deprecated subprogram?
Well, now are you thinking to yourself: "Big deal. That's easy to ignore."
True. But we can take things a step further: I can tell PL/SQL to treat that warning as an error:
ALTER SESSION SET plsql_warnings='ERROR:(6020)' /
When I do this and compile my program unit, suddenly compilation fails. The warning (PLW-06020) has been transformed into an honest-to-goodness compile error (PLS-06020).
Of course when I do that, I have declared that all subprograms and program units (aka, packages) declared as deprecated via the pragma are no longer deprecated. They are "gone", off-limits, unusable.
In other words, you can easily and quickly (well, depending on how much code you've got) identify all program units still relying on deprecated functionality.
Just convert that warning to an error, then recompile your schema (or schemas) and see which ones end up invalid. As in:
ALTER SESSION SET plsql_warnings='ERROR:(6020)' / BEGIN DBMS_UTILITY.COMPILE_SCHEMA ( schema => USER /* Or another */, compile_all => TRUE /* the default */, reuse_settings => FALSE /* the default */); END; /
As PL/SQL code bases grow and evolve over time - and they will, 'cause they are not "going anywhere" & play a mission critical role in your applications - structured, reportable deprecation will become more and more important....
So take advantage of this fine, new Oracle Database 12c Release 2 feature as soon as you can.
Which is today, if you sign up for the Oracle Database Exadata Express Cloud Service. Catchy name, right?
And no, you should resist the temptation to use an acronym. ADEECS just doesn't do it. :-)