Programming Terminology – What Does Mapping Mean?

mapobject-orientedterminology

I often hear things like:

  • Mapping the classes
  • Mapping the objects from the database
  • Mapping the objects
  • Mapping the elements of a list
  • A mapper

What does a mapper and the act of mapping something actually mean?

Best Answer

The programming uses of the verb "map" and the noun "mapper" are largely unrelated to their common uses in English, so this is a very understandable question.

The programming use is also very broad, so let's start with the most concrete and well-defined meaning of "map". Namely, the higher-order map function present in most functional programming languages. Here's a trivial example of it in Javascript:

var numbers = [1, 2, 3, 4];
var timesTwo = function(n) {
    return n * 2;
}
numbers.map(timesTwo); // [2, 4, 6, 8]

The map function requires an array and another function. It returns a new array which is the result of applying that function to all elements of the original array.

All other uses of the term can, at least in my experience, be considered analogous to this specific one. In the most general sense, "mapping" in programming means taking several things and then somehow associating each of them with another thing.

A typical but imprecise usage in my day-to-day work would be "mapping UI events to handler functions". For instance, when the user clicks button 1, I want handleButton1Click to get called, and when the user hovers over an image, I want handleImageHover to get called.

One of the most high-level uses of this term is ORM (object-relational mapping), which means mapping rows in a relational database to objects in an OOP language, so that you can manipulate "normal" objects in your code without having to directly write SQL or worry about the structure of the database.