http://superuser.com/questions/60006/what-is-the-purpose-of-the-www-subdomain
The www. sub-domain stil exists mostly for historical reasons... and the function above is just removing it from the hostname in case it gets returned (interesting to know if it ever does!), so the code is reasonable.