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?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityI often hear things like:
What does a mapper and the act of mapping something actually mean?
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.
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.
User
is a representation of a row of the database table USER
, that would be object-relational-mapping. I guess your native tongue is spanish given your username, mapping or "to map" could be translated as emparejar.
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.
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.