Questions tagged [hard-coding]
40 questions
49
votes
4 answers
What does "hard coded" mean?
My assignment asks me to access a test.txt document, so the file name has to be hard coded to my C drive. I have no idea what hardcoding means. Can somebody please help me with this?

LilProblems
- 657
- 1
- 8
- 11
16
votes
20 answers
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…

mezoid
- 28,090
- 37
- 107
- 148
11
votes
17 answers
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…

Jeff
- 13,079
- 23
- 71
- 102
7
votes
7 answers
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 = "{0,…

mezoid
- 28,090
- 37
- 107
- 148
6
votes
4 answers
How to avoid hardcoding strings
This is a question regarding best coding practices.
I would like to know the consensus about how to best avoid hardcoding strings and values in a .NET application.
What I've seen so far where I have previously worked:
using resource .resx…

Amc_rtty
- 3,662
- 11
- 48
- 73
6
votes
4 answers
External file for strings, as opposed to hardcoding them
I have experience developing some Android apps, which handily have XML string files where you can store strings. The last time I developed a desktop Java app I hard-coded the strings (for example button titles, labels etc...). I have since learned…
user485498
5
votes
3 answers
How to hide literals in code
What are the main existing approaches to hide the value of literals in code, so that they are not easily traced with just an hexdumper or a decompiler?
For example, instead of coding this:
static final int MY_VALUE = 100;
We could have:
…

Mister Smith
- 27,417
- 21
- 110
- 193
4
votes
3 answers
Java: Using key names from properties file without using hardcoded strings as keys
Problem statement
I have a properties file that's accessed throughout my java project.
Example contents of my .properties file:
appName=MyApp
appType=TypeA
Let's say I access the single property, appName, all throughout my java…

richsinn
- 1,341
- 1
- 12
- 27
3
votes
9 answers
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…

JamesEggers
- 12,885
- 14
- 59
- 86
2
votes
5 answers
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…

nimcap
- 10,062
- 15
- 61
- 69
2
votes
4 answers
What exactly is hard coding?
I believe that it's a value that is assigned and
that cannot be changed.
An example would be:
int limit =5;
for(int i =0 ; i

g_90
- 23
- 1
- 4
2
votes
4 answers
How to avoid hard-coding tons of dict key strings in Python
May be it is a common question, but I am new in python!
I am working on some libraries that handle json queries and asked myself if there is some best practice to avoid hard-coding tons of json keys like:
# just an example..
var1 =…

Dmitry
- 93
- 1
- 7
2
votes
1 answer
SQL Server: avoiding hard coding of database name in cross-database views
So, lets say you have two SQL Server Databases on the same server that reference each others tables in their Views, Functions and Stored Procedures.
You know, things like this:
use database_foo
create view spaghetti
as
select f.col1, c.col2
from…

codeulike
- 22,514
- 29
- 120
- 167
2
votes
9 answers
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 …

Tony Andrews
- 129,880
- 21
- 220
- 259
2
votes
2 answers
Hard coding in IOS app
We have an IOS app which connects to API/server through SSL connection. The SSL keys have been hard coded in the APP, the SSL certificate has expired and now the app is not functioning.
Q1. We want to avoid submitting the APP to the store as it…

ViSu
- 462
- 2
- 4
- 17