什么是hardcode?
hardcode
原文:http://whatis.techtarget.com/definition/0,,sid9_gci214512,00.html
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. Hardcode is also sometimes used in describing more difficult programming languages such as C or C++ rather than such "softcode" languages as Visual Basic.
翻译
原文:http://www.cppblog.com/saga/archive/2007/12/22/39281.aspx
在计算机程序或文本编辑中,hardcode(这个词比hard code用起来要频繁一些)是指将可变变量用一个固定值来代替的方法。用这种方法编译后,如果以后需要更改此变量就非常困难了。大部分程序语言里,可以将一个固定数值定义为一个标记,然后用这个特殊标记来取代变量名称。当标记名称改变时,变量名不变,这样,当重新编译整个程序时,所有变量都不再是固定值,这样就更容易的实现了改变变量的目的。尽管通过编辑器的查找替换功能也能实现整个变量名称的替换,但也很有可能出现多换或者少换的情况,而在计算机程序中,任何小错误的出现都是不可饶恕的。最好的方法是单独为变量名划分空间,来实现这种变化,就如同前面说的那样,将需要改变的变量名暂时用一个定义好的标记名称来代替就是一种很好的方法。通常情况下,都应该避免使用hardcode方法。
有时也用hardcode来形容那些非常难学的语言,比如C或者C++语言,相对的,用softcode来形容象VB这类简单好用的程序语言。