computer 6150387 1920

Print Out Your Code on A Paper

If you are a coder you might have noticed reading code is much harder than writing it, even if it’s written by you, still it takes nerve to read code thoroughly. To curb it, desk checking or printing your code on a paper and reading it is easier. Once you print the code piece you cannot just read it but also see the sense in it. Check out below we have steps to desk check or how to print your code on a paper:

  • Get a Pencil 
  • Print Out Your Code
  • Sit in a Quiet Room 
  • Start Reading Code on a Paper

Leave everything behind, leave your laptop, phone and every other thing that might distract you. Just keep a pencil in your hand and then print out your code. Now read the printed code line by line and keep marking it with the pencil. While doing this you will come to know that you can read and learn much more this way.

Some of The Important Practices While Reading Printed Code 

Check Labels – In many ways the English lexicon itself is more complex than any coding language. We have learned that most of the code misunderstanding arises from incomprehensiveness of English between the programmers rather than programming language itself. Make sure that the labels are right. 

Check Abstractions – You might notice that the first time you saw code on your screen there was a problem domain due to ambiguity. But now you are getting it right since it’s in your hand. Naturally, we are more inclined to read everything in our hands. We can do code refactoring to add more clarity to our printed code. We can decompose and omit unnecessary code that did not appear to be unnecessary before printing it. 

Find Bugs – One important aspect of printing and reading code on a paper is it lets you identify bugs easily. You will realize how it happened in the first place. So this is the best way to find bugs in your code. 

How to Print Code With Highlighted Syntax

Use the popular command line utility called enscript which is ancient but effective. It might be already installed on Linux or download enscript for Linux. While on Mac you need to brew install enscript. 

enscript -1rG --line-numbers -p out.ps --highlight=python \
  -c inputfile.py

The output is going to appear like this

enscript output

You can open it as out.ps (or open as default PostScript viewer on Mac) or default print it with lpr out.ps.

Enscript comes with various options such as:

  • -1 -2 -3 -4 number of columns per page
  • -r rotate (landscape mode)
  • -G fancy header (with filename, date & time)
  • –color=1 if you have a color printer
  • -w html to print in PostScript instead of HTML
  • –help-highlight to see syntax highlighting options

Check this one that adds –color=1 and -2. If everything is aligned choose this one.

enscript -2rG --line-numbers -p out.ps --highlight=python \
  --color=1 -c inputfile.py

Code can be quite beautiful at rest—if you take the time to really appreciate it. You can print out a beautiful piece of code and read it in your hands while using these utilities that can be really a fun way to read code well and hunt down code bugs.