What makes code “hard coded” compared to other code, why is it so difficult to change, and why would developers hard code something rather than use normal code?

In order to understand how something is "hard coded", you need to understand what we do to the code in order to make it run on your device. Code is written in a human-readable format, but there is a lot of optimization and changes that get done to the code before the device can run it. This process is called compiling and linking. The result of compiling and linking code is an executable file that the device can understand, but humans cannot. The executable that has been compiled and linked is a snapshot of the code at the time that was compiled and linked. Any changes to the code require compiling and linking again in order for the executable to reflect it.

The program often needs to make choices based on internal values while the game is running. Most of the time these values are data-driven, meaning they are read from files outside of the code (e.g. read in the information from this config file and store it as whether to run the game in windowed mode). When the game needs to decide whether to run in windowed mode, it checks the file, grabs the relevant data, and uses that to decide. Because it's pulling this information from that config file, the same executable can handle both windowed and non-windowed mode. We don't need to compile and link the executable again.

If running windowed mode were hard coded, somewhere in the code itself there would be a variable like "Windowed = true". Then, after compiling and linking the executable, that executable would always run in windowed mode and never be able to run in full-screen mode. The only way to change this would be to change the code, then compile and link the executable again. Hard coding is fast and easy to do as a first pass of things, it's a quick way to test stuff locally if you can compile and link the executable yourself.

We can't give out the code because it's copyrighted and our intellectual property. We can only give out the executables after compiling and linking because they can't be read by humans. This means that any changes made to code are fairly difficult to distribute - this is what patches are. Hard coded values can only be changed when we distribute a new executable, while data-driven values like settings in a config file are much easier to change because they don't require compiling and linking, they only require somebody to modify the file being read and not the executable itself.

[Join us on Discord] and/or [Support us on Patreon]

Got a burning question you want answered?

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *