What is your attitude towards hard coding?

Jeff picture Jeff · May 6, 2009 · Viewed 14.7k times · Source

Mine is this:

Hard coding is the way! All my problems go away. Just code it one by one. And problems come back kill your day.

I absolutely hated it but the fact is "business people" tend to like it because it takes less time to get what they wanted. And as a software developer especially working in a corporate environment, most people will say: "yeah, why bother, just hard code it". What is your attitude toward hard coding?

Answer

Chathuranga Chandrasekara picture Chathuranga Chandrasekara · May 6, 2009

Hardcoding is something that should be avoided as much as possible.

If you hardcode something on your code it will completely "destroy" the portability of your code in a great extent. Even with a platform independant languages you will not able to say "Compile once, Run anywhere". Since it is not a good software engineering practice, I think avoiding hardcodes is better.

But I know in some cases we need that, specially in debugging the codes. The way I suggest is: First develop the code with hard codes, make it stable and eliminate the hardcodes then...

And there might be some cases that we need hardcoding, due to security concerns etc :). you might not be allowed to use registry, configuration files, any thing because they can increase the attack surface. But I think it is a rare case.