After looking through both examples I listed, I think that Apache's URL rewriting guide's example is better since it checks if the canonical name is used, and if not, it redirects to the canonical name, whereas the other example (and which is also NogDog's idea, though his implementation is slightly faulty) checks for the specific uncanonical form. On the other hand, that example neglects the 301 (moved permanently) code, so perhaps the best would be:
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]