sed -e s/foo/bar/ | sponge filename
GNU sed -i is an architectural violation of the idea of a stream editor, and it isn't available everywhere.
precisely to preclude anyone from suggesting using GNU sed -i.
Also by relying on external tools, you have now forced your users down the dependency hell path.
If you know of, or have such a case, I would be really interested to see it, out of purely professional interest.
Nobody wants to debug shell scripts.
I want to debug shell scripts, because of all the debugging I've done over the years, shell script debugging is by far the quickest / easiest:
DEBUG="${DEBUG:-false}"
$DEBUG && set -x
and one can see the machine state immediately. Best debugging experience by far.