Observables and dimensional analysis Here is a simple question about physical units that I hope has a simple satisfying answer. In mathematically sophisticated treatments of both quantum and classical physics one often speaks of an algebra of observables and this leads to thinking about Jordan algebras, C* algebras and so on. As a mathematician I tend to not think about physical units too much but isn't there something funny about, for example, considering arbitrary functions of p and q when one considers units (to take classical phase space for example). For example, what sense is there in adding p and q which have different dimensions? Or even something like p+p^2.   Supposedly, every smooth function on phase space, that is every smooth function of p's and q's, is supposed to be an "observable". But most such functions will be dimensionally incongruent as long as there are any units at all. I can think of some rather as hoc or otherwise unsatisfying excuses but I don't think I have come up with the best way to explain this to myself. In any given algebraic expression one can throw in various "constants" to bring things into line but nothing about the mathematical notion of an algebra of functions involves such distinctions. The whole thing seems awkward.   What is the right way to think about this?
By the way, it is occasionally strikes me as odd that  we graphically represent in the same space the vectors of velocity, acceleration and angular momentum  as if all lived in the same vector space. The very definition of a vector implies one may add any two vectors but again there is this issue of dimension. 
 A: A dimensionful real-valued quantity takes values in a $1$-dimensional real vector space (a ‘line’) rather than in the space of real numbers as such.  Given two such quantities taking values in the line $L$, their sum also takes values in $L$; given a quantity taking values in $L$ and a quantity taking values in $L'$, their product takes values in $L \otimes L'$ (which is also a line).  Dimensionless quantities are included in this, since $\mathbb{R}$ is itself a line, in fact the unit of the tensor product.
So, instead of the Jordan (or whatever) algebra $A$, we really have an algebra $A^\bullet$ (I am making up this notation here), which is a completion of the direct sum over all lines $L$ of $A \otimes L$.  It is worth checking that whatever functional calculus you rely on in $A$ also extends to $A^\bullet$, which is true if you include enough lines; for example, if $q$ takes values in $L$ (and never takes the value $0$), then $1/q$ takes values in the dual space $L^*$ (which is also a line).
Formally, we can add quantities with different dimensions, obtaining a result in $L \oplus L' \subseteq A^\bullet$ (and even do things like $\sin q$ if $A^\bullet$ is completed appropriately), but what's important is that each expression in which the units balance has a $1$-dimensional subspace of $A^\bullet$ in which all of its values lie.
To relate this to Qiaochu's answer, Qiaochu's $A$ is my $A^\bullet$, and my $A$ is the subspace of Qiaochu's $A$ that is fixed by the action of $G$.
A: What we mean when we say that two quantities have different units is that if we change something about how we measure quantities, the two quantities will behave differently. For example, if one quantity has a unit of length and another has a unit of time, then when we change how we measure lengths we'll modify the first quantity but not the second. 
Formally, we can think of thinking about units as introducing the action of a group, let's say $G = (\mathbb{R}^{+})^n$, where $n$ is the number of units you're considering. Each factor of this group rescales a different unit. Formally we can think of unital quantities in this setup as an algebra $A$ equipped with an action of $G$. That action equips it with a grading with respect to the characters of $G$, and this grading is what we mean by units. In particular, once we remember this group action there's no reason to restrict our attention to homogeneous elements of $A$. If we want to do this anyway, we can always multiply by unital constants (which are also elements of $A$). 
A: The way most physicists would think about this, is to choose units where Planck's constant is 1, so $p$ has dimension of 1/length, and then assign a characteristic length $a$ to the system. If the problem is formulated on a lattice, $a$ could be the lattice constant, but any other length will do. Then whenever you see $p$ you think $ap$ and whenever you see $q$ you think $q/a$.
A: Here is another, completely different answer.
As Carlo indicated, one can use units in which Planck's constant is $1$.  This is no arbitrary choice, but one dictated by fundamental physics.  Similarly, one may set the vacuum speed of light to $1$.  It is a historical accident (mainly due to our being massive creatures bound to a planet) that we think of length and time as being of different dimensions (in the sense of nonstandard analysis), so that we write $E = m c^2$, but really it's just $E = m$.
Conversely, it's a historical accident (this time a lucky one) that we don't think of force as having its own dimension, so that we have $f = m a$ instead of $f = m a/g$ (where $g$ is Galileo's constant, about $32 \operatorname{lb}_{[M]} \operatorname{ft} \operatorname{s}^{-2} \operatorname{lb}_{[F]}^{-1}$, with a dimension of $[M] [L] [T]^{-2} [F]^{-1}$).  This probably only happened because a clear distinction between the pound-force and the pound-mass came after Newton's laws (but before such other units such as the slug, the poundal, the gram, the dyne, and of course the newton).
In electromagnetism, people often make do with only the dimensions $[L]$, $[T]$, and $[M]$, because they set Coulomb's constant to $1$.  (Depending on where you put the $c$s, this is either the electrostatic, electromagnetic, or Gaussian system of dimensions; combined with $\operatorname{cm}$, $\operatorname{s}$, and $\operatorname{g}$ as the respective units of $[L]$, $[T]$, and $[M]$, this is called the electrostatic, electromagnetic, or Gaussian system of units.)  Only the fuddy-duddies at the BIPM insist on making electric current an independent dimension $[A]$.  (They also use $\operatorname{m}$, $\operatorname{s}$, and $\operatorname{kg}$ as the base units, so people write about this as ‘cgs vs mks’, when that's not what it's about at all.)
Similarly, set Boltzmann's constant to $1$ to show that energy and temperature have the same dimension, and set Newton's gravitational constant to $1$ as well.  Since of course $1 \operatorname{mol} \approx 6.02 \times 10^{23}$, all $6$ of the physical dimensions implicitly endorsed by the BIPM in the SI system of units (the candela depends on human biology) can now be seen to be utterly dimensionless!  (The $6$ constants are Planck's, Maxwell's, Coulomb's, Boltzmann's, Newton's, and Avogadro's, and they are log-linearly independent, giving a unique solution to the system of $6$ homogeneous log-linear equations made by setting them all to $1$.)
The point is:  Every quantity is dimensionless, and every unit is simply some real number, so we may calculate with them as if they were real numbers because they are!  (In fact, they are all positive real numbers, justifying our use of them in division and inequalities.)  The $A^\bullet$ in my first answer is just $A$, and the group in Qiaochu's answer is trivial.
Here is a problem:  Although the constants we set to $1$ do come from fundamental physics, there is still some choice (even controversy) about how we do this.  First, Planck's constant $h = 2 \pi \hbar$ derives from work on cyclic wave phenomena, and the really basic quantity is Dirac's constant $\hbar = h/(2 \pi)$ (which is also often called Planck's, so Carlo may have meant this all along).  Similarly, Coulomb's constant $1/(4 \pi \epsilon_0)$ derives from work on spherically symmetric charge distributions, and the really basic quantity is $1/\epsilon_0$ itself (which, following the Gaussian system on placement of $c$, gives us the Heaviside–Lorentz system of dimensions when we set it to $1$).  A similar remark applies to Newton's constant $G = c^2 \kappa/(8 \pi)$; Einstein's constant $\kappa$ is the more basic one.  Planck himself, who first came up with all of this, not only used $h$ and $G$ instead of $\hbar$ and $\kappa$, but also used the charge of the proton instead of $\epsilon_0$ or Coulomb's constant, clearly a great error.
So while every unit is a real number, different people disagree over which real numbers they are!  (And not just because of experimental uncertainty, which is also an issue somewhat.)  All of the possible different conventions to eliminate a given set of dimensions are mediated by a group of symmetries, the group in Qiaochu's answer, so keeping track of them all brings us back to the sophisticated answers that he and I gave.
But the point is:  You don't have to choose a convention.  Since some convention is possible (and you already knew this when you saw your first system of units, however arbitrary it may have been), it is valid to say that every unit is a real number (even though which real number depends on the convention chosen), and so we may calculate with them as if they were (positive) real numbers.
A: To me, an "observable" is just a device---often an actual, physical device, like a magnetic field meter or a radar gun---that outputs a number. For example, if I have a device that measures the airspeed of a plane in knots, measures the altitude of the plane in fathoms, and then outputs the sum of those two numbers, that's an observable. From this perspective, it makes perfect sense that an observable should be modeled in classical mechanics by a function on phase space, which precisely captures the idea of a number that may depend on physical circumstances.
Confusingly, there's another type of thing in classical mechanics which is usually represented by a function on phase space: a Hamiltonian. Although Hamiltonians are sometimes called observables, I think there's an important sense in which they're not observables: they have units! I'll try to explain what I mean by this, but I'm really shaky on the details, so corrections are welcome.
Like Toby Bartels said here, a dimensionful quantity is a physical quantity that lives in a one-dimensional real vector space, and a choice of units is a choice of isomorphism between that vector space and $\mathbb{R}$.
In symplectic mechanics, we model phase space as a manifold $M$ with a symplectic form $\omega$. This doesn't involve any "unnatural identifications with $\mathbb{R}$," so no units show up.
The story is different, however, when it comes to time. In classical mechanics, time is naturally thought of as a one-dimensional affine space, but in symplectic mechanics we typically identify it with the vector space $\mathbb{R}$. That's a choice of units! (And a choice of origin, too.)
Once we identify time with $\mathbb{R}$, each function $H \colon M \to \mathbb{R}$ can be interpreted as a prediction about the motion of the system, in the following way. Let $\beta$ be the 2-form $\omega - dH \wedge dt$, where $t$ is the natural coordinate function on $\mathbb{R}$. A tangent vector $v \in T(\mathbb{R} \times M)$ is predicted to lie along a possible worldline of the system if and only if the cotangent vector $\beta(v, \cdot)$ is zero.
Now, what if we want to avoid choosing units, and just think of time as an affine space $C$ modeled on a one-dimensional vector space $D$? Then a Hamiltonian ought to be a function $H \colon M \to D^*$, so its exterior derivative will be a $D^*$-valued 1-form on $M$, which can be interpreted as a 2-form on $C \times M$. Since $D$ is the tangent space of the time line, an element of $D$ is a dimensionful quantity with units of time. An element of $D^*$ eats elements of $D$ and turns them into numbers, so it must have units of inverse time. That means a Hamiltonian has units of inverse time—which is exactly what you'd expect, because energy is the conjugate variable of time!
