Ask HN: How do you print code?

7 points by vlmutolo ↗ HN
I would really like to print out stjepang’s library smol. It’s just a few thousand lines of code and I have a feeling that it would be easier for me to understand on paper.

How does anyone do this? I’ve heard that companies sometimes do code reviews on paper, so I figured this would be a solved problem.

Still, I couldn’t find a decent solution anywhere. So there’s the question for Ask HN. How in the world does anyone print code in a reasonable way?

By “reasonable”, I mean:

1. with line numbers,

2. with syntax highlighting,

3. and preferably some sane separation of source files.

Smol:

https://github.com/stjepang/smol

16 comments

[ 0.21 ms ] story [ 50.3 ms ] thread
By using an IDE or editor with a decent print function. On Windows I've printed I've from Visual Studio and Notepad++. Not sure of a good editor for printing on Linux or Mac.

        $ mkdir rtfs
        $ for F in src/**.rs; do
        >     pygmentize -o rtfs/$(basename $F .rs).rtf -O linenos=1 $F
        > done
        
Now open the .rtf files with a word processor and print them.

To change the highlighting theme, e.g. to "pastie":

        $ pygmentize -O style=pastie,linenos=1 ....
This… might actually work. Thanks!
We had a project work to submit C programs. Originally, the teacher told us to write the programs by hand. I had written ~20 C programs in my computer and was feeling lazy to write out all of them by hand onto paper. I then asked the teacher if I could submit the programs printed on paper and she said yes.

I was already using Pygments to highlight my source code and was thinking if I could print them highlighted with it.

Pygments has many formatters to format output. I used .rtf but you can also output images as well.

I know this is not answering your question, but... I strongly recommend against printing code, why?

You lose facilities like: goto source, search/replace, modifications (I might modify/format a piece of code temporarily, to help me understand it better, might rename functions, variables, add lines to visually separate parts of code, etc) and many more.

You re-enforce your discomfort with reading/writing code on the screen. I'm trying to assume different reasons that you might have to learn a code and for all of them that I can imagine, you'll be better off as someone who feels at home with the screen. So I suggest you to resist this temptation and do what you ultimately will do.

Out of curiosity, Is your job/situation/skills in a way that being good with screen will not seriously benefit you? How?

"You can't grep dead trees." - The Jargon File
And you can’t alt-tab to HN on a sheet of paper ;-)
I do not know how OP would be benefited from printing code, but I had to print my C code to submit as a school project.
I’m comfortable reading code on a screen. I just thought it would be interesting to try printing out a whole library as a packet to get a good understanding of it as a first pass.

You’re right that you lose a lot of tooling on paper. But you can always have your laptop alongside the packet. No need for either/or. Plus, I have found that I retain things better when they’re printed out. I also like to mark up documents in pen. At the end of the day, it’s just a preference thing. And paper might actually work for the use case of just trying to understand a library; the code is static in that situation.

I recently printed some C code for studying. I used GNU Enscript to convert it to Postscript. (Enscript can also send the job directly to the printer, at least on macOS.) Very handy program. I think it can do syntax highlighting for some languages. Are you sure you need that though?
Thanks for the suggestion! I’m pretty sure I need the highlighting. Looking at black and white code is just so much harder for me.
Try it maybe? In an editor then I agree that it is too useful to turn off. But if you print the code you will anyway have to read it many times in order to take it in. You will probably see that you will be able to navigate it even without the syntax highlighting.
When I was a kid in the 80's I use to print my code. It was on a dot matrix printer tractor fed paper. This option would be better, IMO, than loose leaf as the pages stay in order.

I think it is a good idea to print it out to help you understand. I consider it on occasion but don't want to pay for the ink and paper. Plus printers have some unspoken vendetta against me...they hate me and I hate them.