KSP-KOS / KSLib

The standard library and examples for the Kerboscript language
MIT License
118 stars 40 forks source link

Should we put some standard stripper utilities here? #6

Closed Dunbaratu closed 9 years ago

Dunbaratu commented 9 years ago

One thing I often do is run a "stripper" script that compacts all my kerboscript code into a form where all the comments and indenting space is removed.

It occurs to me that maybe either putting utility scripts here (they'd have to be OS-dependant to some extent) that do that for others may be nice, or even more ambitious still, we could make a tool that automatically does this with all submitted code and provides a "stripped" folder with the stripped versions. Note, the original would be preserved as well. This would be a second copy of the script.

It would be nice if people didn't feel constrained to have to write their scripts compactly just to reduce footprint, and instead could make them well indented and commented, especially as putting scripts here is meant to be a useful teaching tool as well as a library.

(while I'm at it - header comment detection and stripping to auto-gen MD document files could be pretty good too - but that should be a separate issue)

austinjames314 commented 9 years ago

If the purpose is to have scripts that use less memory in-game, wouldn't it make more sense to just use .ksm files? I've not used them much, and am aware that they're apparently bigger in 0.17, but wouldn't it make sense to put any effort into making 'compiled' scripts smaller?

abenkovskii commented 9 years ago

@Dunbaratu It would also be nice to have a "merge scripts I choose into one big file" script. This will reduce the number of copy commands to upload a program onto a vessel. It also could automatically search for the dependencies (by searching an argument of run command in the library folder). Plus compiled version of this big file will take a slightly less space because some string constants will be reused. @austinjames314 Yes the information about comments and indents isn't stored in .ksm files.

Dunbaratu commented 9 years ago

KSM is no longer a large reduction in space unless you use a lot of comments. But it might be in the future. I still have some optimizations I could do to the code here and there.

What I am quite interested in, however, is the idea of doing a small program that runs through and strips out doc-comments from the scripts, so you don't need to maintain BOTH a comment in the script describing the arguments, return ,and description of a function, AND repeat that info in the .md file. It would be nice if we could do a thing similar to javadoc, or doxygen, or C#'s xml comments.

Dunbaratu commented 9 years ago

There's a part of me that wants to see if it's possible to fiddle with the compiler in kOS.Safe to make a separate command-line program that will parse the script and make the docs.. but that may be overkill when all it needs to do is read the comment tags and find the name at the start of the next function.

abenkovskii commented 9 years ago

Also: a small script that replaces all white space characters with spaces can considerably reduce the size of .ksm file produced by the compiler by reducing %D section to almost nothing.

abenkovskii commented 9 years ago

Problem: this small script will have to remove comments too so the task is a bit less easy.

abenkovskii commented 9 years ago

@Dunbaratu Does your implementation turn whole file into one long line?

Dunbaratu commented 9 years ago

No. that would be horrible because then any reported errors would be impossible to find - the line number would be wrong. line breaks are the only whitespace I keep, because I want the line number counts to still be right. I rememebr the C preprocessor had a directive to deal with this where you could tell it to reset its line count with a directive - it was used for cases where you have a tool that automatically alters source code, like lexx/yacc, but you want the compiler's errors to report the users' original line numbers, not the ones in the massaged file. You did that by sprinking line number reset directives all over the place when inserting the new code in the automated program.

abenkovskii commented 9 years ago

@Dunbaratu I think there should be an optional "extreme compression". Removing line breaks doesn't make working with .ks easier but it reduces the size of .ksm.

abenkovskii commented 9 years ago

@Dunbaratu I think the stripper in the library might improve the code style by it making comments and indents cost nothing.

Dunbaratu commented 9 years ago

That's what I was thinking. I see some people using one-space indents and I think the only reason they're doing that is code size.

I have really never liked this idea of making people pay for comment space. Yes it's true that the old 60's computers only had a few K, but that space was taken up with low level machine code, not source code with indents and comments, in an object oriented system.

They tested out their code in assembly on a mainframe, spit out the numerical bytes for the ML, and then WOVE those bit patterns into the rope memory by people following instructions on cards in front of them. (put wire A into slot 53, put wire B into slot 71, etc.)

abenkovskii commented 9 years ago
  1. @Dunbaratu

spit out the numerical bytes for the ML, and then WOVE those bit patterns into the rope memory by people following instructions on cards in front of them. (put wire A into slot 53, put wire B into slot 71, etc.)

.ksm sort of does what you said. Am I missing something important?

  1. To be explicit: I vote for including stripper into the repo because an argument: "we have a stripper in our lib so add indent or I'll go mad" is much more powerful argument than "there is a stripper hidden somewhere on the internet so you'd better add the indent"