hard-coding

Is hard-coding literals ever acceptable?

霸气de小男生 提交于 2019-12-30 03:59:09
问题 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 = someCondition ? "Yes" : "No" 2. double myPercentage = myValue / 100; In the first case, is the best thing to do to create a class that allows me to do MyHelper.Yes and

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

本秂侑毒 提交于 2019-12-21 04:26:09
问题 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> <td>{5}</td><td>{6}</td></tr>"; if(items.Count > 0) { builder.AppendLine( String.Format(format, "Date", "Id", "WorkItemId", "Account Number", "Name", "Address", "Description")); } foreach(Item

Are hard-coded STRINGS ever acceptable?

自闭症网瘾萝莉.ら 提交于 2019-12-19 04:21:30
问题 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 option like this: if (config_options.value('FOO_ENABLED') == 'Y') ... (Of course, this same option may need to be checked in many places in the system code.) When adding a new

What does “hard coded” mean?

﹥>﹥吖頭↗ 提交于 2019-12-17 15:28:12
问题 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? 回答1: "hard coding" means putting something into your source code. If you are not hard coding, then you do something like prompting the user for the data, or allow the user to put the data on the command line, or something like that. So, to hard code the location of the file as being on the C: drive, you would

What does “hard coded” mean?

巧了我就是萌 提交于 2019-12-17 15:26:30
问题 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? 回答1: "hard coding" means putting something into your source code. If you are not hard coding, then you do something like prompting the user for the data, or allow the user to put the data on the command line, or something like that. So, to hard code the location of the file as being on the C: drive, you would

External file for strings, as opposed to hardcoding them

你离开我真会死。 提交于 2019-12-12 09:38:48
问题 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 this is bad practice, and I should store strings in a file. I am not sure how to go about doing this. I am currently developing in Eclipse. Should I just stick a text file in my project folder? Is this standard? How do you locate the file in the

External file for strings, as opposed to hardcoding them

非 Y 不嫁゛ 提交于 2019-12-05 08:17:35
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 this is bad practice, and I should store strings in a file. I am not sure how to go about doing this. I am currently developing in Eclipse. Should I just stick a text file in my project folder? Is this standard? How do you locate the file in the code? Moritz Petersen Yes, you should use .properties files and access them using ResourceBundle . Eclipse

Are hard-coded STRINGS ever acceptable?

痴心易碎 提交于 2019-12-01 00:40:47
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 option like this: if (config_options.value('FOO_ENABLED') == 'Y') ... (Of course, this same option may need to be checked in many places in the system code.) When adding a new option, I was considering adding a function to hide the "magic string" like this: if (config_options.foo

Is hard-coding literals ever acceptable?

淺唱寂寞╮ 提交于 2019-11-30 11:22:51
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 = someCondition ? "Yes" : "No" 2. double myPercentage = myValue / 100; In the first case, is the best thing to do to create a class that allows me to do MyHelper.Yes and MyHelper.No or perhaps something similar in a config file (though it isn't likely to change and who knows

What does “hard coded” mean?

▼魔方 西西 提交于 2019-11-27 18:11:37
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? steveha "hard coding" means putting something into your source code. If you are not hard coding, then you do something like prompting the user for the data, or allow the user to put the data on the command line, or something like that. So, to hard code the location of the file as being on the C: drive, you would just put the pathname of the file all together in your source code. Here is an example. int main() {