Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've just been compiling some of my own code with the -std=c++0x flag in GCC, as I want to vaguely keep up with what all the young folks are doing (provided they stay of my lawn), and I ended up with a load of warnings about auto_ptr being deprecated. Of course, I knew that auto_ptr was deprecated in C++0x, but...

Isn't deprecation a waste of time and effort? Reasons for not deprecating (with auto_ptr as an example):

  • there is an ocean of code out there that still needs to be supported, producing millions of warnings will only tempt people to turn warnings off.

  • auto_ptr is a bit naff, but it does actually do what it says on the tin.

  • if we really want to deprecate things, I nominate printf(). But just imagine the squeals that would ensue. auto_ptr doesn't have too many friends, but in at least my C++ code it is used more than printf, which isn't used at all.

  • the committee have a bad record of getting this right - they deprecated static at namespace scope, and now it seems to have been undeprecated - I wouldn't be surprised if auto_ptr made a similar come-back

  • lastly, whatever the committee say, the compiler implementers ignore them - they simply can't risk breaking their customers code, all they can do is issue irritating warnings.

So my question - do you consider deprecation (of anything, not just auto_ptrs, and not just in C++) a good idea, and if so, why?

share|improve this question
2  
@TheLQ - I read it as "why depreciate anything" but using auto_ptr as an example. –  ChrisF Jun 11 '11 at 19:21
4  
does it say on the tin "will break your heart if used in containers of almost any kind"? Use unique_ptr and be happier. –  Kate Gregory Jun 11 '11 at 20:08
12  
@Neil - your language is a little inflammatory and (on reflection) it does come across as more of a rant than a serious question. If you want it to remain open you might want to "tone it down". –  ChrisF Jun 11 '11 at 21:16
4  
@Neil - I appreciate that you had intended it as humorous, but as I said, on reflection it came over more "ranty" than I think you intended. –  ChrisF Jun 11 '11 at 21:43
9  
If you ever plan of getting rid of deprecation, you should really deprecate it first. Lots of existing languages/APIs would break otherwise. With deprecation you could give them some time to get rid of their deprecated deprecations. –  Joachim Sauer Dec 3 '13 at 13:22
show 5 more comments

closed as primarily opinion-based by gnat, GlenH7, Robert Harvey, Kilian Foth, MichaelT Dec 6 '13 at 2:28

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

8 Answers

Reasons for deprecation (in general):

  • It clearly indicates to people that something is bad practice (and hopefully suggests an alternative).
  • The deprecation period gives people a chance to change their code before the compiler removes it outright.

I also disagree about the last point. Compilers don't ignore the committee, and they do eventually remove things that are deprecated (e.g. >?= and <?= in GCC -- they were deprecated then removed*).

I think the important point is: some things should be removed, for various reasons, and I think deprecation is the only sane way to do that. In this specific case, auto_ptr should be removed as it has been superseded by unique_ptr. Changing over is easy enough, and people will have plenty of time to do so.

(*) Yes I know they are extensions and not standard, but the point is that compiler vendors do eventually remove things once they enter deprecation, whether code still relies on them or not.

share|improve this answer
4  
Sorry for the offtopic, but I can't resist: what were those >?= and <?= operators? –  brandizzi Dec 22 '11 at 14:59
4  
In old GCC you could write a >?= b; which was shorthand for if (a > b) a = b; and likewise for <?=. –  Peter Alexander Dec 22 '11 at 15:40
    
Ugh... I can see why they added it. And then why they removed it. Deprecation can be necessary for the "neat" features that only reveal how problematic they are after they are released to the public. –  Phil Dec 3 '13 at 15:05
add comment

Any sufficiently complicated API will likely have flaws that are not discovered until after they've been used for a while. Our options:

  • Leave things as they are. This means the API will continue to gather more and more cruft as it evolves over time. Even if new and improved versions are added, the old ones will need to be kept maintained as well.
  • Remove it without warning. This is likely to break a lot of code.
  • Deprecate it and remove it in a later version. This gives time to fix existing code, while ensuring that the amount of cruft stays bounded.

Deprecation is the sanest of these alternatives.

share|improve this answer
add comment

Nah. Deprecation can be a really good thing. It keeps technologies from getting stuck with old useless baggage.

Just in the C++ arena, I remember Microsoft's "feature" of not correctly supporting variable declaration inside a for statement. That went on for about a decade and made a lot of code non-portable. That's one "feature" I'm glad was deprecated.

More generally, Apple has had a habit since the 80s of marking clunky old APIs as "deprecated" for 5-7 years before yanking them. I was just talking with an Apple engineer at WWDC about deprecating some of the ancient QuickTime C APIs, and was really delighted to hear they were doing that, because continued support for a model developed around 1990 was completely obstructing what one would expect to be able to do on modern 64-bit multicore CPUs.

In practice, it's going to take compiler writers a long time to dump auto_ptr, and they'll probably support some backwards-compatibility mode for a decade or two, but it's a good thing imo.

share|improve this answer
add comment

if we really want to deprecate things, I nominate printf()

printf is a useful function. It allows for formatting things ways shorter than iostreams. And it's a C function. The very reason C++ exists and is used is because it's compatible with C. So deprecating printf seems less useful.

So, anyone else up for an anti-deprecation crusade?

The committee is aware of some of the problems of the current supposed meaning of deprecation. See the meaning of deprecation.

share|improve this answer
    
@Neil now that you have adapted your question, I can adapt my answer :) –  Johannes Schaub - litb Jun 11 '11 at 21:36
    
The "meaning of deprecation" link does not work anymore. It points somewhere, but the document no longer discusses meaning of deprecation. –  Jan Hudec Dec 3 '13 at 14:13
    
@JanHudec: The link should work again –  Bart van Ingen Schenau Dec 4 '13 at 18:16
add comment

Languages and APIs have to move forward. Even though there might be a ton of code depending on some old feature, there might be a new and better way to do something and the cost of supporting the old feature is just too much.

Deprecation also gives warning that in the future, the feature will be removed. This gives developers time to update their code if they are keeping up with the new API. This is much better than the alternative: outright removal. Remember that depreciation is a warning, not an error.

And if this is an old program that you don't want to update, then nothing is stopping you from using the old API (or in this case compiler).

share|improve this answer
add comment

As it stands, deprecation has at least two meanings.

  • It is going to be removed in a future version
  • We created better alternatives and now the feature is redundant (but not entirely useless). Newcomers would better skip this while learning the language; however, it is not going to be removed any time soon.

I think static falls into the latter category, but only time will tell if auto_ptr really deserves to be removed or if it's better to keep it in the language.

share|improve this answer
add comment

Deprecation is not harmful if moving to an alternative can be done in 1 work day: eg. simple search/replace of the old function with the new, or a compatibility layer is easy to set up.

If you need to rewrite large parts of the software because of the deprecation, then it's harmful.

A good example would be probably the PHP's mysql API, basically you simply need to replace all mysql_* with mysqli_* and provide a link id to them and it's done.

One bad example is the deprecation and removal glBegin, glEnd, and all matrix computation stuff from OpenGL, if you want your code work on OpenGL3 or above, you'll need to rewrite the whole rendering code to use vertex buffers.

share|improve this answer
add comment

I think it is a good way of letting people know that there is a better way. I much prefer a nice deprecation rather than a function just disappearing.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.