How to avoid hard coding a particular value? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to avoid hard coding a particular value?

I have written a function as follows isNameTrue= funcIF::getinstance.CheckName("abgh6578") how can I avoid hardcoding the above mentioned "abgh6578"? Can I set it as a constant using #define?

15th Nov 2016, 6:35 PM
Sand
1 Answer
0
Hard coding means writing a program which is not flexible. I.e. there's no way to change the behavior apart from changing the source code. It is highly undesirable because, most of the times it's user who alters the behavior and it could be very unique depending on the situation. There are many ways to overcome this. • Get the value from the user. • Get them from stored files (like settings files). • Get the values from database. • make use of XML/JSON to get the required settings. • you can make use of IsolatedStorage or WindowsSettings if you're working on C#. 😀
15th Nov 2016, 6:42 PM
Nagendra Prajwal
Nagendra Prajwal - avatar