opIndex() may hide opSlice()

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 10 16:37:30 PST 2017


On Friday, March 10, 2017 14:07:59 H. S. Teoh via Digitalmars-d wrote:
> On Fri, Mar 10, 2017 at 12:36:35PM -0800, Jonathan M Davis via 
Digitalmars-d wrote:
> > I can certainly understand that there are folks who really do care
> > about this stuff, but it's completely outside of what I deal with, and
> > for anything I've ever dealt with, making opIndex be for _slicing_
> > makes no sense whatsoever, and the added functionality to the language
> > with regards to multi-dimensional arrays is useless. So, this whole
> > mess has always felt like I've had something nonsensical thrown at me
> > because of a use case that I don't even properly understand.
>
> Please don't denigrate something as useless without at least trying to
> understand it first.

As I said, for what _I_ deal with, it's useless. It's obviously useful to
some subset of programmers - particularly folks doing scientific stuff based
on what I've seen about posts about multi-dimensional arrays - but it's
useless to me. I did not mean to denigrate anything, so sorry if that wasn't
clear. My point is that I don't want to have to worry about it or be
affected by it when it is useless to me - particularly when I'd have to
spend some time studying it to understand it properly. About the only time
I've dealt with matrices in any real way was when I took linear algebra, and
I've forgotten almost everything from that class. It simply has nothing to
do with anything that I've ever needed to program, and I'd just as soon
avoid any kind of math that would require it. So, as long as the
multi-dimensional slicing stuff sits in its own little corner of the
language where I don't have to deal with it, I'm fine. I just want to keep
using opSlice for slicing and opIndex for indexing, because that makes sense
to me and my needs, whereas using opIndex for a slicing operation just seems
wrong, much as it apparently has a benefit for generic code dealing with
multi-dimensional indexing and slicing.

And as long as the current situation with opSlice working for slicing like
it always has continues, I don't care what the subset of programmers who
care about multi-dimensional arrays do with opIndex. Unfortunately, it comes
up periodically that someone pushes for everything to change to use opIndex
for slicing or even to deprecate opSlice for slicing even when the code has
nothing to do with multi-dimensional indexing or slicing, and I do object to
that. If no multi-dimensional indexing or slicing is involved, I think that
opSlice should be used for slicing, not opIndex. Fortunately though, there
hasn't been a real push to move everything to use opIndex instead of opSlice
and get rid of the original behavior, and I hope that that stays the case.

Regardless, thank you for your thorough explanation as to why it was changed
so that opIndex could be used for a slicing operation.

- Jonathan M Davis



More information about the Digitalmars-d mailing list