Noah said:
I'm not talking about the syntax change being a switch to another type
of abstraction. I'm talking about the need for the new abstraction
being created. What is the reason behind needing this 2d array
"class"?
How about two-dimensional digital images? (I think that's what the
original poster has in mind. It's certainly something that I need
two-dimensional arrays for.)
There are all sorts of uses for two-dimensional arrays, as matrices
themselves demonstrate. And there are all sorts of useful things we can
do with and do to two-dimensional arrays. (Of course, we could
generalize to N-dimensional arrays, and it might be preferable to do
two-dimensional arrays as N-dimensional arrays where N happens to be
two. But anyway.)
The problem is that "legacy code" as an issue has been brought up in a
vaccuum. We start by saying we want a 2d array class and then someone
says we have to be aware of "legacy code" and thus are required to do
things a certain way. Legacy code doesn't exist nor change in a
vaccuum. If we where to add a 2d array class to legacy code then there
must have been a reason for it. Chances are high that a "2d array
class" would _never_ be added to legacy code in such a manner as has
been posited here. The requirement governing the change is more likely
to be leaning toward a better abstraction.
It wouldn't necessarily be a matter of adding a two-dimensional array
class /to/ old code. It could be that we want to reuse old code with
our new code. Our new code might need a new implementation of
two-dimensional arrays, but we might still want to apply some of that
old code to our new arrays. If that old code assumes [][]-style
interfaces, then there's really no great loss in including such an
interface in our new array class - especially as it doesn't preclude
using a (,)-style interface as well!
As I understand it, one of the strengths of C++ was supposed to be that
old code could be applied to new stuff without having to be changed (as
long as the old code was written appropriately for such reuse). Runtime
polymorphism and templates are both ways of allowing old code to use new
code. If we're taking advantage of such reusability, we may well find
ourselves wanting to apply that old code to our new arrays.
Of course, we /could/ edit the old code, to have it use the interface we
think it ought to use. But what about other code that uses, or is used
by, that old code? Should we really be editing modules B, C and D just
because we think module A ought to use the interface we want for our new
module E? I don't think so.
And, of course, our new code may eventually be old code that someone
else wants to reuse in the future. For all we know, they might want to
use it with other old code that operates on one-dimensional arrays,
using []-style subscripting. They might want to treat our
two-dimensional arrays as one-dimensional arrays of rows. They might
want to treat individual rows as one-dimensional arrays. If we haven't
provided suitable []-style interfaces, it's not going to be quite so
simple (but they can always wrap our two-dimensional array in a suitable
wrapper class with the right interface).
Simon