ID:170803
 
I was just looking at a bunch of the source's from the 4K challenge, so I decided to try and do something like that. I tried doing a Login proc:

#define D #define

D L Login()
D S src
D M mob


M L S<<"Hello"


I tried also doing:

M;L;S<<"Hello"

So yeah, anyone want to show me how to seperate lines I always thought it was the ";" command thing. I also know that there probably would be no reason for this in an everyday situation if I wasn't doing some kind of challenge like that, but I just thought it might be intrested knowing how it worked.
One of the quirks of code compression is that it doesn't always work as you expect. In this case I think the correct compression would be:
M/L{S<<"Hello"}


Of course, in a real 4K Challenge something like Login() wouldn't be a prime target for compression. I'd focus instead on things that are used a lot. Scream of the Stickster did this:
#define u #define
u i if
u q(a) i(a)del a;
u t world.time
u D density
u E else
u F(a,b) for(a in b)
u G get_step
u H view
u I src
u J icon_state
u K loc
u N name
u O New
u Q world.maxz
u R return
u T locate
u V new
u W while
u X ..()
u Y spawn
u Z sleep
u _ max(b-t,0)
u gd get_dir
u Pf P.Find(I)
u Kn set category=null

It was a tremendous challenge finding single letters to abbreviate further and still have proc/var names to use. Note that if was actually reduced because it's used so often that the overhead of the define statement is nothing compared to a 50% trim for every instance. Note that the biggest winners there are control statements like for, while, else, return, sleep, spawn. I didn't screw with continue or break because they're used infrequently. And for for(), I figured since for(a in b) is the most commonly used form, I could exploit that fact for a quick macro. I didn't end up compressing usr because it hardly comes up; src is used much more often.

Lummox JR
In response to Lummox JR
Personally, I'd just write the code normally, and write a script - possibly in Python - to compress it. Otherwise I'd get terribly confused.
In response to Crispy
Hmm if I read the rules of the 4k Challenge, people couldn't use outside compilers besides dm. Otherwise that would work out good.
In response to Lummox JR
Hmm, I understand all of what you just said. I still can't get it to work correctly. I did:

M/L{S<<"Hello"}


Like you said, and that did not work. I then replaced M with mob so it was not compressed, that worked fine. Also, i'm looking at your source right now; the first thing I noticed obviously is that it is all on one line, just like the other 4k participants. Does that compress it more by putting it on one line? Also what is the difference betweeen ";","{}","[]". I know the last one would be used in for lists, but it doesn't look like it is used for that in your source. Also, could someone give me a good example of how to have more than one thing (I couldn't think of a better word) going on at once. Like:

mob
Login()
src.CharCreate()
..()
proc
CharCreate()
src << "I am Cool"


I will try to do that after I post, and I will edit my post if I figure it out. One last thing. If I did everything on one line, how do I switch to like obj defining, and turf defining?

[Edit]
Alright, I am making progress. I think I have found the difference between the ";","{}". The ; is for seperating lines, while the {} is for basically defining something I think. I also am making progress on the multiple task thing:

mob/L{S<<"Hello";S<<"Test";CC}mob/P/CC{S<<"Test2"}


That did not work, there were a bunch of errors, similar to the mob problem I had before. I then replaced P with proc and that worked. So far I have figured out, mob, and proc you can't compress. I might be wrong though.[/Edit]

[Edit 2]
Something else I just thought of, would it be easier writing it all out (like what crispy said) and then figuring out which proc's,var's and stuff like that, had the highest frequency and then remake it so it is compressed?
[/Edit 2]
In response to N1ghtW1ng
N1ghtW1ng wrote:
Hmm if I read the rules of the 4k Challenge, people couldn't use outside compilers besides dm. Otherwise that would work out good.

Shouldn't make a difference. The point is to compress your .dm code as much as possible while still making it work. Doing that is actually more or less impossible for a script because a script will only save so much, but through talented manipulation you can eke out some huge savings.

Actually I may look into redoing Scream of the Stickster sometime with new code for newer BYOND versions, since a sleep()/spawn() timing bug made the movement system act differently in prior BYOND versions. And now list/Swap() is available, which could greatly simplify score updates.

Lummox JR
In response to N1ghtW1ng
I think one of the things hurting your compression efforts is that you're trying to include () in the compression. I.e., L instead of L() for Login(). This is generally more counterproductive than you'd think. For now leave () out of the compression and see how you get along without it.

As for , and / and ; and {}, the difference isn't quite what you think it is. A set of braces works just like / in indenting what comes next, except anything inside the braces stays at that indent level. So for example, your code in this line:
mob/L{S<<"Hello";S<<"Test";CC}mob/P/CC{S<<"Test2"}

...decompresses as:
mob
L
S << "Hello"
S << "Test"
CC
mob
P/CC
S << "Test2"

For some procs you don't need the braces; for one-liners, you can just follow the initial () with code. (That's one reason to avoid using () in the compression.) A more effective compression might look more like this:
mob{proc/CC()S<<"Test2";Login(){S<<"Hello";S<<"Test";CC()}}

That's longer, but I've undone a few things you're compressing that you don't need to, like Login() and proc. Any procs you define should be all in one place, so you should be able to just use the proc keyword once or twice--not enough to justify compressing it. I'd also avoid using a separate proc for character creation, since it's just a waste of space; it can all be done in Login().

As to your question of whether putting everything on one line saves space: Yes. Since any closing brace } can be followed up immediately with another command, a line break is just a waste of a character. (Actually it's two characters the way DM saves, but good 4K developers convert to UNIX ASCII which has 1-char line breaks vs. 2-char.)

The key questions to ask when compressing code are:
  • How long is this keyword/sequence?
  • How often is it used?
  • How many bytes would a #define for this take up, and what would the savings per use be?
  • What other portions of the code can I rework to use these simple macros instead of uncompressed keywords?

    Lummox JR
In response to Lummox JR
Alright thanks Lummox. That cleared up a few questions I was wondering. One more thing...Shadowdarke said on my other thread about Entered() he said that he wrote Blob out long hand, and then compressed it. Did you do that for Scream of the Stickster.
In response to N1ghtW1ng
N1ghtW1ng wrote:
Alright thanks Lummox. That cleared up a few questions I was wondering. One more thing...Shadowdarke said on my other thread about Entered() he said that he wrote Blob out long hand, and then compressed it. Did you do that for Scream of the Stickster.

Somewhat, yes. I kept it in a semi-compressed form most of the time, and did full compression now and again to check on its size.

Lummox JR
In response to Lummox JR
Ah, ok. Thanks for helping me understand this better. If I have anymore problems, i'll post em.