This approach is, IMO, better than media queries because it allows me to do things beyond CSS and not force the user to a mobile website if they don't want to for some reason. Plus, I can test my mobile version from my desktop by clicking the link to switch. Relying solely on media queries is a bad idea because mobile browsers will still download the entire content of the page (including hidden images) even if it is declared hidden by a CSS directive.
If you still want to do user-agent sniffing, I recommend using either Mobile ESP or WURFL. That way you only have to upgrade a single library and have the latest signatures without expending a lot of extra effort.