hardcode 的定义

习惯于从wiki中查找一些计算机专业用语的定义,以下为我找到的对hardcode的相关定义,利于理解

Hard coding (also, hard-coding or hardcoding) refers to the software development practice of embedding input or configuration data directly into the source code of a program or other executable object, or fixed formatting of the data, instead of obtaining that data from external sources or generating data or formatting in the program itself with the given input.

还有一个从网上摘录的定义:

hardcode:

In computer programming or text markup, to hardcode (less frequently, hard code) is to use an explicit rather than a symbolic name for something that is likely to change at a later time. Such coding is sometimes known as hardcode (noun) and it is more difficult to change if it later becomes necessary. In most programming languages, it is possible to equate a symbol with a particular name (which may also represent a number) value. If the name changes, the symbol stays the same and only the equate line of code needs to be changed to reflect the new name. When the program is recompiled, the new name is picked up wherever the symbol occurs in the code. Although there are search-and-replace tools that can change all occurrences of a given name, program code is very unforgiving in case a small error is introduced, and it is safer to have a single place in which such a change can be made. For this reason, hardcoding is usually a practice to be avoided.


举个例子,对于n-皇后的问题,如果,你在编写程序的时候,制定queen_number =6,那么你的程序就是hard coding;

然而,如果,你的程序的queen_number需要用户输入的,例如cout<<"please input queen number"<>queen_number;这样就不是hard coding。,也好像是#definie NUMBER 6这样的用法

不知道是否理解正确,请大家指正^_^

你可能感兴趣的:(hardcode 的定义)