4

Sometimes I hit some questions with code samples in the question or some of the answers that are deprecated.

Example: The before destroy callback

In this question from 2009 about some feature of Ruby on Rails we find several details in the code samples which are deprecated in the latest versions of Rails.

For example:

def before_destroy

should now be

before_destroy :do_something

def do_something
  ...
end

or this one:

errors.add_to_base("A project with effort logged cannot be deleted")

should now be

errors.add(:base, "A project with effort logged cannot be deleted")

I'm sure other questions and technologies have similar problems. Is there a recommended way what to do about this? While an experienced developer won't have too much of a problem here, for some people it may be quite confusing if he tries to run some of this code and gets strange error messages or deprecation warnings from Rails.

3

4 Answers 4

11

The questions themselves should not change (so substantially), that's the essence of the query; however, the community would likely thank those who update existing solutions with a more up to date variation, or postings of new answers giving such coverage (obviously with a bit of an explanation as to why (i.e. that other methods are deprecated.))

One thing you have to consider here, and this has been brought up times before, is that deprecated or not, people might well be lumbered with such 'legacy version' technologies, and require the solution fitting for such - and, therefore, they have a deserved place.

A notable problem is that posters often fail to specify their version, which doesn't exactly serve to clarify things in the long run - as that experienced developer, this is something that would need to be determined so as to allow you to project an answer 'more correctly', otherwise we're left with questions re technologies with no version specified and an answer per breaking-change version without any reasonable descriptors to discriminate. I suppose tags without versions could be considered another problem in and of itself, however.

5

Well those desprecated features might not be deprecated on older versions of Ruby (same goes for other technologies)

And they still may be valid for users using the older version.

Maybe tag them with a tag that denotes it as an old version.

3

In the case you described, you can add a new answer and report that, in the new versions of RoR, things are changed (explaining exactly how).
The OP already got the answer that helped him; future readers will read also your answer, and know that the other answers reported for that questions are obsolete/not anymore valid.

3

When you see deprecated code in the question, you can probably just leave it alone. As other answers have said, it applies to a particular older version of RoR that some programmers are probably still using. It would be good to make sure that the question is tied to the specific version of RoR for which the now-deprecated code is valid, by editing it to include a version-specific tag.

When you see deprecated code in an answer, then you should edit it. That is, after all, why posts are editable. In order to avoid disturbing the existing answer too much, I might suggest appending something like


Note: the above is valid in version X.Y. In more recent versions, this is preferred:

updated code sample

to the existing answer.

3
  • Ehhhh I do not agree with editing answers in this way. That seems like too much of a dramatic change...
    – Naftali
    Dec 8, 2011 at 18:34
  • 1
    Well, my understanding is that this is exactly why SE gives us the ability to edit.
    – David Z
    Dec 8, 2011 at 18:43
  • 1
    It's this kind of editing that makes for the betterment of the web (and industry); updating an answer that has umpteen up-votes and/or is accepted would generally make for greater exposure and coverage of angles than simply adding your own, and this is often the preferred way to go, in my opinion. @amanaPlanaCAnalPAnaMA this suggests an addition, with nothing being reduced from the original form. Dec 8, 2011 at 21:23

Not the answer you're looking for? Browse other questions tagged .