3 ms·
The changed return convention is potentially a breaking change. If there are some documented circumstances under which the function returns null, then you can
by kazinator 3y ago
The changed return convention is potentially a breaking change.
If there are some documented circumstances under which the function returns null, then you can write a program which produces those circumstances and expects the null value. That program will break if there is no more null value.
The only way it can be a non-breaking change is if there are no such circumstances; the function never actually returned null, but only threatened to do that in its documentation or the way it was declared, or both.
In fact, changing a function that returns a string to one that returns a string or nil, can be a realistically useful non-breaking change.
It can be a non-breaking change if the null value is not produced for any client which adheres to the existing API documentation. So that is to say, the circumstances by which the function returns null are entirely new.
For instance suppose we have a function like this:
number identity(number)
It's an identity function, that only works for numbers. We cannot call identity(nil); that is an error. Since it returns number, it will never return nil.
This is a totally non-breaking change:
any identity(any)
the function now just returns its argument, no matter what that is. It will now return nil---but, only if invoked as identity(nil), which was previously erroneous.
The conditions are paramount. When we analyze the call, the conditions are easy to think about: is the situation that the program is passing nil, which was previously not allowed, or not? When we analyze the return, it's not so easy: we have to think about: is this returning nil under existing conditions under which it previously could not have done that? Or is it only returning nil under new conditions?
The conditions which pertain to the call are always those of the call. The conditions which pertain to the return are also those of the call, plus the semantics of the function!