Let me give you an example of kind of big- picture thinking as a way
to enable changes that you think you can't make.
Very often,
people will say I can't change the signature of a function because I
can't go and change all the places that call it.
You know we've talked about changing out params to
returning some sort of abstraction.
We talked about changing things that return error codes
to things that return optionals or, again,
some other kind of abstraction or maybe that use exceptions.
Or a very simple tactic much earlier in the course was,
you know, don't have a whole pile of little parameters,
especially all the same type,
when it would be better to have that take more abstracted types.
So maybe there are, say, seven calls that are in your control.
They're in the hot spot part of the code that you're working on,
and you can change them.
So if we change the signature to f, and let's maybe change its name,
you know, ideal universe,
you can change these seven calls to pass different parameters to f.
Great, but there are three calls that you cannot control.
They could be in another application that you're
not allowed to change right now.
They could be in customer code.
They could be anywhere.
It doesn't matter.
Even just another part of this app that you're not allowed to touch right now.
You can still change it.
Here's our function.
It takes four integers.
That's confusing.
You don't know if they're the x and y coordinates of the
top- left and bottom-right corners or if they're the
corner plus a height and a width.
People get confused about the order of them.
You want to replace it with hopefully don't call it f that takes two points.
If you controlled all of the call sites,
you could just change the signature of f,
keeping the old body and maybe adding a couple lines at the
beginning to pull pieces out of the points.
But you can't.
You have to leave the old f there.
But you can take the entire old body of f and put it in this new one,
the one that takes two points.
And in the old one, just make it a wrapper.
It just instantiates points and then calls them real function.
It doesn't even have to be this long.
This will work.
This brace bracket initialization,
because there's an overload of f that takes two points,
the compiler will figure it out and make points out of i1 and i2
and out of i3 and i4 and then call that f.
So the old code that can't be changed can still call the wrapper.
And the new code that can be changed can call the simpler,
easier-to-understand-and- use version of the
function that takes the abstractions.
Now you get all the benefits in your internal calls of having those abstractions, but you didn't break the external calls at all.