LoginLogin

How do I keep my code tiny?

Root / Programming Questions / [.]

GuzzlerCreated:
I just want to know the best way to keep a program small. The smaller the program, the shorter the download time.

The program itself usually isn't the issue. Stuff like graphics is what makes things take a long time to download. Besides, I wouldn't worry about the download time. Even with games containing fully custom graphics, it doesn't take THAT long to download. Worry more about making something that works and that you enjoy rather than shrinking your code.

There are probably tricks to keeping a program small such as keeping variable names short, but I have found that keeping the code simpler and more readable is far more valuable in the long run. I makes it much easier to debug and upgrade later. And randomouscrap is right, programs take up a small amount of the total data and thus download time.

Alright! Thanks guys.

The replies are 100% correct. Storage is cheap and plentiful, whereas processing power is limited. There are no real benefits to be gained from doing this. But it's an interesting question! :-) I can think of two ways: Firstly, generate your graphics and other large data with code when your program is first run. Save the generated graphics to files, and then use those files on subsequent program executions. (I'm in the middle of typing up a tutorial on using Simplex noise to create graphics with SB - thoroughly impractical, but fun) Secondly, write a compression/decompression program which uses the PRGGET and PRGSET functions to read in your game's code and write out a shortened version of it. In its simplest form, it could map all of the SB function names to shorter versions. If all of the functions were translated to integers in the 0-255 range, then you could use the RGB() function to quickly pack three or four of them into an 8-bit hex number... ...and...if you could convert a whole program into a stream of RGB()-encoded information, then you could conceivably make a way for programs to be shared via PNG image, bypassing SB's official method of distribution...

Sometimes download times are fast, sometimes they seem slow. It seems heavily dependent on whether or not the server is in a good mood I guess (maybe SmileBoom isn't very good at netcode?)

Ok, so if you really just want to keep programs short, here are a couple tips: -use 1 letter variable names -remove extra spacing -Remove all spacing -use the syntax highlighter to see whether code will work. For example, X=1:Y=1 can be X=1Y=1