How NOT to Code - Challenge 16

Mar 02, 2010

Been busy doing a IP address switch over at work, which naturally caused  me to find more things to rant about ;)

If you are directly calling an IP address in any manner in your coding, PLEASE STOP ;)

No I'm serious. Yes, IP changes are rare but not unforeseeable. By basing any programming logic on an IP address, you have made your code extremely fragile. to any type of change What's worse is when I see it baked into Flash/Flex apps. Typically the client doesn't have the source code and they end up SOL. In most cases, it's completely superfluous - just make a relative call and the code becomes very flexible to domain name or ip changes.

If you must use an IP or domain name in your coding, put it in a config file outside of the compiled swf. This is specially true for the Flash/Flex world.

You might even go an extra step and be more critical about calling the CGI variables directly. Sami Hoda has an interesting post about using a CGI facade - http://www.bytestopshere.com/post.cfm/cgi-facade-why-you-should-use-one. This is a very important concept of you ever intend to grow the site's infrastructure with clustering or reverse proxies.

 

Comments

Brad Wood

Brad Wood wrote on 03/04/106:10 PM

I prefer to use DNS entries instead of IP addresses. We recently moved our servers to a new data center. We converted everything to DNS ahead of time, with low TTL's. Then on the day of the move, we simply updated DNS and all mapped drives, data sources, mail servers, etc all continued working.
John Mason

John Mason wrote on 03/04/106:30 PM

But even using domain names can be problematic which is the main point I'm driving at.
Brad Wood

Brad Wood wrote on 03/04/1011:27 PM

I guess I should have clarified. For HTTP URLs used for links, images, and redirects-- I agree, relative is better. For the other stuff like data sources, mapped drives, mail servers, or cfftp/cfhttp calls where SOME kind of host designation is required I recommend using DNS. We use a local zone in our internal DNS so I don't refrence by database as 192.168.5.21, instead it is DB001.myCompany.local. If I ever need to switch my main DB server over to 192.168.5.22, I simply update DNS and leave my dozens of datasources alone.

Write your comment



(it will not be displayed)