Why does Munkres define functions in a seemingly complicated way? In Munkres's extremely careful and well-written textbook, Topology (2nd Edition), he defines functions as follows. First he defines a rule of assignment as a subset of a cartesian product $r\subset C\times D$ where each element of $C$ appears as the first coordinate of at most one ordered pair belonging to $C\times D$. The domain and image set of $r$ are then defined as the set of all first coordinates and all all second coordinates of $r$ respectively. Finally, a function is defined to be a rule of assignment together with a set $B$ that contains the image set of $r$. $B$ is called the range of $f$, and the function is finally denoted by $f\colon A\to B$ if $A$ is the domain of $f$. Thus a function is defined by first taking a relation in $C\times D$, shrinking $C$ to the domain $A$, shrinking $D$ to the image set, and then enlarging the image set to a possibly different (from $D$) set $B$. This seems very complicated to me. I don't see what the relevance is of introducing the sets $C$ and $D$ to begin with. A much more natural definition would be simply that a function $f\colon A\to B$ is a relation $r\subset A\times B$ such that every $a\in A$ is the first coordinate of exactly one ordered pair.
I know Munkres did this for a reason, but I have not located where in the book he uses the more elaborate definition. I know many readers of math.stackexchange are pretty familiar with Munkres's book, so I wonder if anyone has any insight as to why the more complicated definition is useful.
Edit: As Asal Beag Dubh suggested, I want to emphasize that my question is what is the point of introducing $C$ and $D$ instead of sticking with $A$ and $B$. 
 A: I can see a purpose for $C$, though I don’t know whether Munkres ever actually does anything with it. (I have the first edition.) At times one wants to consider partial functions from a set $C$ to a set $D$, meaning functions whose domains aren’t necessarily all of $C$. These are what Munkres is picking out as rules of assignment. One may quite reasonably wish to reserve the notation $f:A\to B$ for the case in which $A=\operatorname{dom}f$, so if $f$ is a partial function from $C$ to $D$, one would write $f:\operatorname{dom}f\to D$, not $f:C\to D$.
I don’t, however, see any real point to distinguishing $B$ from $D$: I can’t offhand think of a setting in which one would consider partial functions from $C$ to $D$ with different codomains; different ranges, yes, but not different codomains. (My codomain appears to be Munkres’ range, and my range appears to be his image set. I think that my terminology is more common.)
A: I'm currently reading Munkres' book (for the second time, as I didn't finish it the last time around). Did you ever come to a resolution on this mystery?
I agree with you that this definition is a bit weird. As mentioned above, the definition of a function needs two pieces of data in order to talk about the notion of topology (amongst other things). These data are: (1) a set of ordered pairs, and (2) a codomain. The domain is less important to explicitly specify because it can be given by the first coordinates of the set of ordered pairs. It feels to me that the most concise way of definition a function is the way we have all seen before:
Definition. Let $A$ and $B$ be sets. We say that a set of ordered pairs $f\subseteq A\times B$ is a function from $A$ to $B$ if for all $a\in A$ there exists a unique $b\in B$ such that $(a,b)\in f$. We write $f:A\rightarrow B$ to mean that $f$ is a function from $A$ to $B$.
Definition. Let $f:A\rightarrow B$. We say that the set $A$ is the domain of $f$ and that the set $B$ is the codomain of $f$, which we denote by $\text{dom}(f)$ and $\text{codom}(f)$, respectively. The image of $f$ is defined as the set $$\text{image}(f) := \{b\in B\,:\, \exists a\in A\text{ s.t. } (a,b)\in f\}.$$
These definitions are all that we need. Furthermore, in my personal opinion, these definitions makes it more clear as to what the primitive notions of a function are.
As you mentioned, it is strange that Munkres starts with these sets $C$ and $D$ (and a rule of assignment) as primitives, then shrinks them both (to the domain and image, respectively, of the rule of assignment), then takes $B$ as a another primitive object (which depends on the rule of assignment's image), and uses all this to define the function. It seems like he is working too hard to define a function from $A$ to $B$.
One possible explanation for this approach is if the concept of a "rule of assignment" were to be used later. But I don't think it is (nor have I seen this concept in other settings). If it was, then perhaps it makes sense to start there and define a function from that notion. Of course, a rule of assignment is, in some sense, a weaker notion that that of a function (in that there may be elements of the set $C$ that do not appear as first coordinates in the rule of assignment). Maybe Munkres liked the idea of starting from this as opposed to immediately starting with the stronger notion of a function? I.e., show how this weaker notion, along with the primitive $B$, gives us a function. But then never use it again...
Something I do appreciate, however, from Munkres' approach is that he is careful about specifying the codomain. In many real and complex analysis books, for example, statements about the continuity, measurability, etc of functions are stated without explicit mention of what the codomain is. For example, when studying indicator functions, is it's codomain the set $\{0,1\}$ or the set $\mathbb{R}$ or the set $\mathbb{R} \setminus \{\pi,17\}$ or the set $\mathbb{R}\cup \{\pm\infty\}$ or the set $\mathbb{C}$, etc? Now, under the usual topology, $\sigma$-algebra, etc on these spaces (and the resulting subspace topologies and sub-$\sigma$-algebras, etc) continuity or measurability of the function with a codomain containing it's image set implies the continuity or measurability of the function with any other codomain containing it's image set. So in that sense, sometimes it is innocuous to fail to explicitly mention what "universe" is being operated in. Regardless, it is refreshing to have a book like the one Munkres wrote where he is very clear, from the onset, what the various sets are so that there is no confusion.
A: But the two definitions are actually same in terms of resulting objects. It doesn't matter if you start with $r ⊆ C × D$ or with $r$ a set of pairs. And any such $r$ that in addition $⟨x, y⟩ ∈ r$ and $⟨x, y'⟩ ∈ r$ implies $y = y'$ is a function. So there is no difference between this bare function and Munkers' rule of assignment. $f: A \to B$ just means that $f$ is a function such that $dom(f) = A$ and $rng(f) ⊆ B$. The only remaining issue is the difference between a bare function and a function which remembers its domain and codomain. For example if you want to say that a function is surjective you need the latter interpretation which is also instance of morphism from category theory (morphism knows its domain and codomain). So it seems that there are two kinds of objects which are closely related – the bare functions or rules of assignmens as Munkers says, and the set morphisms or functions as Munkers says. Note that if you want to say that a function is continuous then this function has to know its domain and codomain not only as sets but also as topological spaces.
