What is hardcoded hardcode?

Source: Internet
Author: User
What is hard encoding?

The so-called hard encoding, hardcode, is to write a piece of information that should (CAN) be written to the configuration information directly in the program code.

For example, if you write a program for sending and receiving emails, the user name, password, server address, and so on, it is best to make an external configuration, but if you directly write it to the program code, every time you change the information, you need to re-compile it ...... This program is not easy to maintain. Generally, lazy programmers or beginners have a large program output.

In computer programs or text editing, hardcode (which is more frequently used than hard Code) is a method that replaces variable variables with a fixed value.

After compiling with this method, it is very difficult to change this variable in the future.

In most programming languages, you can define a fixed value as a tag and replace the variable name with this special tag. When the tag name changes, the variable name remains unchanged. In this way, when the entire program is re-compiled, all variables are no longer fixed values, making it easier to change the variable.

Although the search and replace function of the editor can also replace the entire variable name, there may also be many or few replications. in computer programs, the appearance of any small error is unforgivable.

The best way is to separate the space for variable names to achieve this change, as we mentioned earlier, it is a good method to replace the variable name with a defined tag name.

Generally, you should avoid using the hardcode method. Sometimes, hardcode is used to describe languages that are very difficult to learn, such as C or C ++. softcode is used to describe simple and easy-to-use programming languages like VB.

Hardcode is a solid code. Some Code cannot be written to death, or it may be difficult to modify it. For example, if you write a link to www.abc.com and use it in all places, if the domain name changes next time, you need to find all www.abc.com and change it to a new domain name.

However, if you use a constant to store www.abc.com, and all links reference constants, you only need to modify the constants later.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.