Emulating older version bugs for backward compatiblity

Discussion in 'Mac Programming' started by wrldwzrd89, Oct 2, 2009.

  1. wrldwzrd89 macrumors G5


    Jun 6, 2003
    Solon, OH
    I'm working on one of my programs... and, in order to preserve backward compatibility while modernizing the code base, I had to emulate a bug in the older versions to keep things working. Anyone else ever had to do this? If you have, what were your experiences like? Hopefully, the fix for your code was as simple as it was for mine... here's what I had to do:
    1. Add a flag to indicate whether or not backward compatible mode is enabled
    2. Add code to set and clear this flag at reasonable times
    3. Add a little if statement to check this flag, and emulate the older behavior if it's on, else use the new behavior
    Since my code is already highly modular, these changes were very straightforward to make.
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Yes, I've had to implement bug-for-bug compatibility. My strategy depends on the situation. I've done the "modal flag" like you did. Sometimes that's a good option. The main problem I've seen with it is when there are multiple threads that want different behavior. That can turn into its own set of bugs.

    My preferred strategy, if it can be done at all, is to keep the existing API as the bug-compatible one but deprecate it, then add a new function or method with the new bug-fixed behavior. Then new code can be written to use the new functions, old code that was already compiled continues to get the old behavior, and any new compilation will get a deprecation warning. It also has the advantage of not being modal (no flag variable), so it's completely thread-safe with no locks or other threading contention. YMMV.

Share This Page