-1

I just want to clarify my concept about backward compatibility, for which I have created a small example. This example is not intended to show any real use and I have ignored all other aspects of the program to keep it as simple as possible.

If there is a function in the first version of an application:

def print_data(data):
    if isinstance(data, list):
        for item in data:
            print item

Which can be used like:

data_to_print = ['one','two','three','four','five']
print_data(data_to_print)

And in the next version the implementation changes to support Strings

def print_data(data):
    if isinstance(data, list):
        for item in data:
            print item
    elif isinstance(data, str):
        print_data(data.split())

so now it can be used in two ways:

# old style
data_to_print = ['one', 'two', 'three', 'four']
print_data(data_to_print)

# new style
data_to_print = "one two three four five"
print_data(data_to_print)

can this be called a valid example of backward compatibility?

If not please give a simple example for the same.

2
  • 3
    The new version would break applications which were using print_data as a way to pass parameters and only print them if they are arrays and silently ignore strings. In that sense, it's not backwards compatible. If you were to add a new method print_string_data that would be backwards compatible because existing code wouldn't be using that method anyway.
    – apokryfos
    Jun 24, 2016 at 13:32
  • Does it still work with the previous use if the function? If yes then the newer version is backward compatible. This case the update is backward compatible since anything using the function with a list would get the same results. Jun 24, 2016 at 13:41

1 Answer 1

1

See the wikipedia page about backward compatibilty.

As far as your example is concerned, it would mean that data changes its format from list to string accross the whole software and for backward compatibilty reasons, print_data would still allow for the case where data is in its previous list format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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