1

The C# docs have a page on indexers, which appears to use "indexer" to refer to the construct required to enable instances of a class to be accessed via square bracket notation.

Indexers allow instances of a class or struct to be indexed just like arrays.

// Define the indexer to allow client code to use [] notation.
public T this[int i]
{
   get { return arr[i]; }
   set { arr[i] = value; }
}

On the other hand, the pandas docs use "indexer" in several ways. Firstly, DataFrame attributes such as ix, loc and iloc that exist to enable different kinds of indexing operation on DataFrame instances are called indexers themselves. For example, see the first line in the docs for ix:

A primarily label-location based indexer, with integer position fallback.

Yet "indexer" is also used elsewhere to refer to the argument passed within square brackets:

.iloc is strictly integer position based (from 0 to length-1 of the axis), will raise IndexError if an indexer is requested and it is out-of-bounds, except slice indexers which allow out-of-bounds indexing.

Both of these uses are also found in the source code, so this is consistent.

The Wikipedia page for indexers does not help distinguish between all of the examples above, although the page in general does seem biased to the usage in the C# docs.

In object-oriented programming, an indexer allows instances of a particular class or struct to be indexed just like arrays.

What is an indexer? Are all of these usages correct? What am I missing?

1
  • 1
    Looks to me like "indexer" has multiple different meanings. In C#, an indexer is an indexed property whose parameter is written in between square brackets. Wikipedia's "Indexer" page is talking about C# indexers. In pandas, an indexer seems to be something else; I don't know what. Jun 30, 2017 at 17:50

1 Answer 1

4

There is no universally accepted definition of "indexer".

Each language/framework might overload the name for its own use.

As you point out, it usually has something to do with the ability to "index" a thing. But that is as far as any similarity between its uses go.

7
  • 4
    Context. Without context the word indexer could refer to the job of the guy that writes the pages in the back of the book that are titled: "Index". Jun 30, 2017 at 17:52
  • @CandiedOrange Just as "computer" is guy that does calculations.
    – Euphoric
    Jun 30, 2017 at 17:53
  • Thanks! I hoped this would not be the case as I feel that it would be useful to have a more concrete vocabulary to refer to these constructs Jun 30, 2017 at 18:00
  • 1
    @Ninjakannon: That seems to be a common desire of software developers: to have a specific name for every specific thing. If English were as precise as a programming language, then it might be a worthwhile endeavor, but it isn't. Jun 30, 2017 at 18:28
  • 2
    @Ninjakannon I think at the root of this is that the term index is very overloaded. Since 'indexer' means (roughly): 'something that creates indexes', it follows that it's also overloaded.
    – JimmyJames
    Jun 30, 2017 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.