Shop OBEX P1 Docs P2 Docs Learn Events
Formatting Spin Code for a Printable Document — Parallax Forums

Formatting Spin Code for a Printable Document

Hi all,

I haven't been posting in a while. The new format of the forums scared me off, I guess I am afraid of change! Still been lurking about and reading though.

I will soon be in the process of writing my dissertation on my experiment control software (see: http://learn.parallax.com/educators/inspiration/propeller-experiment-controller) and the experiments I have conducted. The focus will be a little more on the software than the actual research. I would like to include some printed version of my code as an appendix with the dissertation. I want to do this primarily because my dissertation is a little atypical (for my department it is usually a series of experiments), and having a massive appendix of code will help ensure that no one claims my dissertation project wasn't enough work to be considered an adequate dissertation.

So I am pondering a good way to include Spin code in a printed document. Of course, it does not look good copy/pasted directly from BST to MS Word. My code, along with my in-line comments are often long enough that they don't fit cleanly on a single line unless the font is very small. I am debating writing a Python script to transform my code into something more printer friendly. Perhaps I will have the script remove the in-line comments. I'm not totally sure.

Anyone have any suggestions? What would you do? Also, while we are at it, if I do make a Python script, does any one have any requests? If it is something others might have a use for I would be happy to post some code.

Comments

  • Varnon

    I have never worked with BST, so I am unsure of what type of formatting is available, but in my opinion, formatting is of the utmost importance, when attempting to make printed code legible. There have been many discussions and arguments pertaining to the formatting of code, especially when it pertains to the use of space or tabs for code indentation.

    Once again, in my opinion.... To make code legible for printed documentation, the indentations should be tabbed, instead of using spaces.

    If your code is formatted with tabs, instead of spaces, you should easily be able to do a cut and paste in MS Word and make it look nice. If BST uses tabs for indentation and you like the way it looks, simply copy and paste the text into your MS Word document, and then format the text to your preferences.

    For example....

    Let's say you are using the Times New Roman font, with a font size of 10 or 12 for the main body of your document, but now you want to add legible code that will fit into your document. Simply select the the pasted code, by dragging your mouse over it, and thus highlighting it. Once the text is highlighted, you can alter the properties of the text, such as changing the font to New Courier and the font size to 8.

    In addition to the code being formatted with tabs, another important aspect to making the code legible is the formatting of very long lines of comments or code. Very long lines of code or comments should be spread over multiple lines, with proper indentation through the use of tabs.

    Bruce
  • Bruce,

    Thanks for your thoughts. I've been tinkering around with it.

    It looks like BST uses spaces in the data file. (Simple IDE uses actual tab characters.) When you press the tab button to add tabs, BST adds a bunch of spaces to simulate tabs at certain levels (you can define the tab points in the editor), but the data file is actually spaces. (There is also a null character after each character for some reason). It still works well enough for copy/paste with a monospaced font (which I prefer for coding anyway).

    I think I am going to have to cut ALL the comments, both inline and prologue comments. I didn't write any of it thinking about how to translated it into a margin-bound form. And then I'm going to have to drop the font size down to 9 or 10 to get some of the longer, multi-indented, lines of code to fit. But I can use the prologue comments for the actual paper, and just keep a comment-free version of the code as an appendix. So everything should be fine. I'll just have to script through the files to pull out the comments.
  • If you can install the proptool, that will also load the Parallax font. (I don't know if BST also loads that font). I have found that it is a very compact but readable font. Much more so than courier and is also a fixed character width font.

    When I want to print code, I cut and paste it into Word, then change the font to Parallax and set it at 10 point. With a little reduction in right/left margin size, I can print most code without long lines wrapping.

    Tom
  • varnon wrote: »
    (There is also a null character after each character for some reason).

    Go to Tools -> IDE Preferences -> IDE Preferences and check the "Save as UTF-8" box. It will make BST save files as UTF-8, which encodes normal ASCII characters as normal ASCII characters, instead of as UTF-16, which adds a NULL after every normal ASCII character.
Sign In or Register to comment.