
Ask HN: How do you print code? - vlmutolo
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.<p>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.<p>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?<p>By “reasonable”, I mean:<p>1. with line numbers,<p>2. with syntax highlighting,<p>3. and preferably some sane separation of source files.<p>Smol:<p>https:&#x2F;&#x2F;github.com&#x2F;stjepang&#x2F;smol
======
aljgz
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?

~~~
AnimalMuppet
"You can't grep dead trees." \- The Jargon File

~~~
cpach
And you can’t alt-tab to HN on a sheet of paper ;-)

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

~~~
vlmutolo
This… might actually work. Thanks!

~~~
smlckz
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.

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

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

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

~~~
vlmutolo
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.

~~~
cpach
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.

------
ApolloRising
This will do what you want.

[https://marketplace.visualstudio.com/items?itemName=nobuhito...](https://marketplace.visualstudio.com/items?itemName=nobuhito.printcode)

------
zhte415
print()

