hard-coding

Is hard-coding literals ever acceptable?

The code base I'm currently working on is littered with hard-coded values. I view all hard coded values as a code smell and I try to eliminate them where possible...however there are some cases that I am unsure about. Here are two examples that I can think of that make me wonder what the best practice is: 1. MyTextBox.Text = someCondi...

Are hard-coded STRINGS ever acceptable?

Similar to Is hard-coding literals ever acceptable?, but I'm specifically thinking of "magic strings" here. On a large project, we have a table of configuration options like these: Name Value ---- ----- FOO_ENABLED Y BAR_ENABLED N ... (Hundreds of them). The common practice is to call a generic function to test an ...

How do I create an html report without hardcoding the html?

I'm currently refactoring a console application whose main responsibility is to generate a report based on values stored in the database. The way I've been creating the report up til now is as follows: const string format = "<tr><td>{0, 10}</td><td> {1}</td><td>{2, 8}</td><td>{3}</td><td>{4, -30}</td> ...

What is your attitude towards hard coding?

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 peo...

How to avoid hardcoded field names in HQL, Hibernate?

Suppose that I have the following HQL: String hql = "select e.aField from MyEntity as e"; If I want to refactor and change the name of the MyEntity's member variable aField to something else, I also have to change all occurrences in the whole code in Strings. If I forget to change one hql string the code breaks. How can I avoid this ...

Benefits to using a database table instead of just hard coding a simple list of data if the data is consumed by 1 app.

For a while, I've been told by a number of people that a listing of U.S. States (and territories) should be stored in a database table and cached for applications that use the information. The only reasons they give me for this is to promote normalization and because "it's how we've always done it". Now if the list changes often becaus...

How to refer dynamically to another database user?

I've a case in which I need to refer to another database user. I've to hard code database user name in view while referring to it. SELECT * FROM eg001t3.DUAL; // example. Is there a way to refer to that db user (eg001t3) from view dynamically or based on a database setup? ...

What's the point in hard coding values which may change?

Hi, When coding systems which use configuration information, it is always a best practice to soft code these on some medium like Xml so these values can be edited without recompiling the entire system. However, plenty of values like Urls are hard coded and these can change. What's the benefit in coding this way? This obviously reduces ...