HACKER Q&A
📣 vlmutolo

How do you print code?


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


  👤 aljgz Accepted Answer ✓
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?


👤 fm2606
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.


👤 smlckz

        $ 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 ....

👤 cpach
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?

👤 ApolloRising

👤 zhte415
print()

👤 non-entity
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.