Here are some ideas and a few questions I've been pondering lately related to the teaching of functions in college algebra and precalculus:
Based on my experience, the teaching of functions usually starts with the discussion of relations, and leads to eventually defining a function from $X$ to $Y$ as a relation that associates each element of $X$ (the domain) with exactly one element of $Y$ (the codomain). From here there tends to be a lot of focus on questions that involve determining whether an equation "defines $y$ as a function of $x$", or "is a function". The focus on these types of questions seems to often lead students (including me when I was taking college algebra) to think of a function as "an equation that passes the vertical line test", or "an equation where each input has exactly one output". This seemed like a pretty productive way of thinking about functions, until I got into more advanced math courses and they started describing a function as "a set of ordered pairs". Also, since I had the understanding that a function is "an equation where each input has exactly one output", I often thought of the rule $f(x)=y$ itself as a function (this idea is reinforced throughout college algebra textbooks. They repeatedly refer to the rule $f(x)=y$ itself as a function), when this technically isn't true. In order to properly define a function, we need to explicitly state the domain and codomain, correct?
This led to even more confusion as I looked back on the type of questions I was asked in college algebra and precalculus. The formal notation that we see in courses like real analysis that usually looks something like "Define $f:X \to Y$ by $f(x)=y$". This notation was essentially non existent in college algebra, precalculus, and most of calculus. I never once thought of a function as a set, nor did I think of the domain and codomain as being part of the formal definition of a function.
As I continued to think back, more questions came up. For example, does it really make sense to ask a student to "find the domain of the following function?" Isn't the domain something that should be included in the defining of the function itself? Also, what does "the domain" even mean? This seems to imply that each rule $f(x)=y$ has one single domain set associated with it. I guess the convention is to find the "largest" one with the "least" number of restrictions? (I know I'm not being precise when I say "largest" and "least" here, but hopefully y'all understand what I'm trying to say)
Another issue is finding the inverse of a function, or determining whether two functions are inverses of each other. Does it even make sense to ask this without explicitly stating the domain and codomain? I mean, $f(x)=x^2$ has an inverse function if we restrict the domain to the non-negative reals, but if I were to just ask "Does the function $f(x)=x^2$ have an inverse function?" (textbooks often ask these kinds of questions), I would expect almost everyone to answer "no", because it is not injective. Then again, whether a function is injective or surjective also depends entirely on the domain and codomain, which in this case are not explicitly stated.
Many of the textbooks I've referred to seem to mirror the issues I'm pointing out, but it is still possible that my experience is the exception, not the rule. Either way, this all leads me to wonder if there are ways to introduce and build on the concept of a function that are more productive, and I'm curious to hear some other perspectives from people with more experience.
TLDR: Understanding the formal definition of a function is extremely important for understanding concepts like one to one, onto, inverse functions, and perhaps many more, but it seems as though we often don't put much (or any) emphasis on it in college algebra, precalculus, or calculus. Perhaps this is something we should make note of and try to improve so that our students are leaving these courses with a productive and accurate way of thinking about functions.