Noah said:
Gianni said:
The (,) syntax is usually called a "functor", not a "subscript"
operator. It is clearly the intention of the language designers that
[][] be used to access arrays and (,) used to call a functor. It
appears strange to me why you would ever want to use a functor when a
subscript operator is clearly intended for it's purpose.
Well, if you want to go there...basing arguments of design on what the
language designers intended...then forcing [][] on a class has no place
in any code since if the language designers had intended a class to
override [][] they would have provided the means to do so.
The language designers have provided a means to override [][], it has
been demonstrated earlier in this thread and is described in 13.12 of
the FAQ.
Needlessly changing a body of code using [][] to (,) is far more
complex. It's also not exactly a complex concept.
Again, your only argument that holds any water involves legacy code and
the FAQ has already excepted that case.
Why would I ever want to build a body of code that would exclude the
largest set of customers ? Legacy code using [][] syntax is here for a
very very long time.
Only so long as it is not changed. I work on legacy code every
day...some of the nastiest stuff ever written at times. It is rather
easy work, though boring, to change function call signatures and go
from [] to f(). I know this because I do it every day. So unless you
are selling a library that has a bunch of legacy code based on it you
don't need to worry about it...and as you showed, you can always
implement the deprecated interface for those that do if you are in such
a situation or if you don't want to change everything immediately.
We're loosing sight of the argument here. Sure, knock yourself out,
change your code to use (,) vs [][]. I certainly would be far more
cautious of changing code like that.
The use of (,) over [][] is simply a preference. The C++ standard never
mentions (,) as a subscript operator. This news group is about the C++
standard. As a preference, it should remain at most a suggestion, and
not run into a fallous diatribe over the merits of (,) over [][]. That
is the argument we have here.
No, when dealing with legacy code the issue of syntax is a minor one.
That is again an opinion. I personally approach wholesale changes like
that you describe with more caution. If I can make the change in the
library (in one place), then I would need a really good reason to start
changing large bodies of code. Simple syntactic preference is not a
good reason IMHO.
There really should be a very solid reason to
deviate. All the reasons given so far to use (,) in preference to [][]
hold no water IMHO.
(,) is easier to implement and lowers the complication of the code.
This one is clearly debunked. It takes 20 lines of code which is IMHO a
very low threshold.
There is no need for a special row proxy when you change from the row
major form or to provide safety. It is also miles better than the most
common implementation of [][] though not a whole deal greater than the
best...it's just less complex and therefore the better alternative. IE
keep it as simple as you can but no simpler.
Again the simplicity argument is in the eye of the beholder. I can't
argue about what you feel but I can say I have a vastly different
opinion of the merits of simplicity and where and when it should be
applied. This line of argument ends in the "Mariani complexity
proposition".
The Mariani simplicity/complexity proposition: There exists a minimum
complexity when modeling multiple interactive systems.
Lemma 1. When modelling interactions between multiple systems, there
exists a minimum level of complexity of the interfaces where the
overall complexity of the entire system is also minimal.
In other words, if you make your interfaces too simple, your overall
solution is more complex.
This again would lead to a conclusion about personal preferences.
More to the point. You shouldn't be implementing a "2d array". You
should be looking for a better abstraction. Once you have that better
abstraction there is no need, nor desire, to advertize that it is a 2d
array. I think the fact that there is no 2d array in the standard, nor
does there seem to be one comming in the forseable future, is quite
telling.
Sure, go for it. Regardless, there is a huge body of code that says
differently. Again this boils down to syntactic preference, not a
technical argument of the deficiencies of [][].
Your insistance on implementing a basic function as a complex set of
operator overloads reminds me of the subscript operator implemented in
some of the legacy code I work on. Implemented [] for a list that
returns the object with the serial id supplied...it's of course linear.
Then base mass "legacy" code on it in a bunch of for loops. Took me
about 4 hours to pull that member out and change all the [] calls to
functional equivilants. Time well spent IMHO...bad design is bad
design and we shouldn't stick to it just in the name of "legacy" unless
we absolutely have to.
If I was your supervisor I would have asked you to revert your change
unless you had a very good technical reason. All you have stated was a
technical preference.
At any rate, like I said...unless you are in the situation of dealing
with legacy code there is no need to worry about it. So why go to all
the trouble of forcing the [][] issue?
I think I am clearly on the side of C++ in that [][] has been used far
more than (,) and is the default syntax. You need to make an argument to
change it from [][] which is substantiated by more than just personal
preferences.