View Single Post
Old 07-20-2016, 08:05 PM
Jragon Jragon is offline
Join Date: Mar 2007
Location: Miskatonic University
Posts: 10,293
Originally Posted by Kedikat View Post
It is quite variable.
It depends on how well the original code was written. There are methods for coding which make debugging, updating and actual operating better. Others noted that there are a few different packages to do it. But if you write bad spaghetti code. It is more difficult to code your update as well as install it. Though devices have so much power these days. Bad code and big updates, can still seem to go fast and smooth.

There are programs that can write and modify their own code on the fly.
I don't think code quality has too much bearing on whether executables can download their own updates. It's fundamentally an issue of just downloading the new version, and then swapping the files, and deleting your own on exit (or execution of the new one). If you want to be fancy you can build a patch file that's smaller than an entirely new executable and do that, though in that case you likely need a small executable whose sole purpose is applying the patch and relaunching the executable.

The more difficult part is managing mirrors, verifying checksums, and other little things to ensure you don't accidentally download a wrong file and otherwise making sure you don't accidentally replace a working executable with a broken one.

It's also somewhat easier if you don't need to modify the executable much and a lot of things are done in a scripting language or in other external files like pictures or 3D models, this is why, e.g., Blizzard games can be run when only partially updated, their updater prioritizes files it absolutely needs to run and downloads art assets on the fly as it needs them.

While self-modifying programs exist, in practice they're really hard to write due to compiler optimizations mucking with program structure in most languages. If you want to do such a thing you're usually looking at assembly or some really ugly low-level C. You may have some luck trying to overwrite intermediate bytecode like Java has, but trying to dynamically rewrite your own program in higher-level compiled languages like Haskell, Rust, or Go is probably an exercise in frustration.

Last edited by Jragon; 07-20-2016 at 08:07 PM.