15

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?

1
  • 2
    It means matching items from one set with items in another set - or it means performing a function on each item in one set to get a new corresponding set. Which is kind of the same mathematically speaking. So it might mean matching tables in a database with objects in code. Or performing an operation on each item in a list. A mapper is a function or class which matches items in one set with items in another.
    – JacquesB
    Jan 17, 2016 at 16:42

4 Answers 4

14

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.

11

It's a mathematical concept.

www.thefreedictionary.com

2. Mathematics The correspondence of elements in one set
to elements in the same set or another set.

It's to establish a correspondence between two distinct data models.

  • For example, you can say thay the class User is a representation of a row of the database table USER, that would be object-relational-mapping.
  • Or you can create a key-value pair list which is saying that a given element of one list corresponds to one element of the other list.

I guess your native tongue is spanish given your username, mapping or "to map" could be translated as emparejar.

2
  • 4
    Your description would likely only be understandable to someone who already has experience with mapping. Jan 17, 2016 at 15:58
  • @RobertHarvey I kind of improved it. Jan 17, 2016 at 16:04
5

Generally, "mapping" is some association of some values to other values. It tends to imply a manual sort of process. It tends to imply a fixed association. Consider ASCII values:

'a' -> 97
'b' -> 98
'c' -> 99
...

The entire set of associations is called a mapping (noun). Having the characters and the numbers and making the associations is also called a mapping (verb). It differs from a function, as a function takes some input and produces the output based on some calculation. Mappings generally do not do a calculation, but instead some sort of look-up.

0

A geographical map translates real world landmarks to a different format: an easy to read piece of paper.

Mapping in science is the same idea. You take a set of objects from one domain and translate them to another for a different use.

It is a broad concept that can be used generally for any number of situations.

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