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?
相关问题
- Operator precedence in C Definitions
- Selector for “Define” Edit Menu item in iOS 5
- Order of Class Definitions in C++
- What is the correct terminology of XML's eleme
- Defining types from other units in Delphi
相关文章
- In which way is akka real-time?
- Unit Testing - definitions
- What is the difference between “compile time” and
- HTTPbis - what does bis mean?
- namespaces, classes and free functions - when do y
- What is the rationale behind tentative definitions
- What is the meaning of “exclusive” and “inclusive”
- Enum inside class (TypeScript definition file)
the opposite ,antonym of Hard coding is soft coding , Hard coding vs soft coding so I think for a better understanding of this is better to read both meaning
In feature design, softcoding has other meanings.
Example :
https://softwareengineering.stackexchange.com/questions/67982/is-it-ever-a-good-idea-to-hardcode-values-into-our-applications
// vs NOT using hardcoded data value
//another example
https://www.quora.com/What-does-hard-coded-something-mean-in-computer-programming-context
1.“Hard coding” is a well-known antipattern against which most web development books warns us right in the preface. Hard coding is the unfortunate practice in which we store configuration or input data, such as a file path or a remote host name, in the source code rather than obtaining it from a configuration file, a database, a user input, or another external source.
The main problem with hard code is that it only works properly in a certain environment, and at any time the conditions change, we need to modify the source code, usually in multiple separate places.
In soft coding, we put things that should be in the source code into external sources, for example we store business logic in the database. The most common reason why we do so, is the fear that business rules will change in the future, therefore we will need to rewrite the code.
In extreme cases, a soft coded program can become so abstract and convoluted that it is almost impossible to comprehend it (especially for new team members), and extremely hard to maintain and debug.
I have found some interesting explanation here , you can met Hard coding in different environments , IDE or programming languages . You mention a situation and I want to add something else
https://www.hongkiat.com/blog/code-optimization-coding-antipatterns/ https://en.wikipedia.org/wiki/Softcoding
"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.
The file name is "hard coded" as:
C:\myfile.txt
The reason the backslash is doubled is because backslashes are special in C strings.
Scenario
In a college there are many students doing different courses, and after an examination we have to prepare a marks card showing grade. I can calculate grade two ways
1. I can write some code like this
2. You can ask user to enter grade definition some where and save that data
Something like storing into a database table
In the first case the grade is common for all the courses and if the rule changes the code needs to be changed. But for second case we are giving user the provision to enter grade based on their requirement. So the code will be not be changed when the grade rules changes.
That's the important thing when you give more provision for users to define business logic. The first case is nothing but Hard Coding.
So in your question if you ask the user to enter the path of the file at the start, then you can remove the hard coded path in your code.
"Hard Coding" means something that you want to embeded with your program or any project that can not be changed directly. For example if you are using a database server, then you must hardcode to connect your database with your project and that can not be changed by user. Because you have hard coded.