Hacker News new | ask | show | jobs
by tambourine_man 814 days ago
PostScript is deep magic that I admire from a distance.

This is some mad scientist stuff. Great work.

4 comments

> PostScript is deep magic

Why do you say that? It's a very simple and tiny language that you can learn in an afternoon. Far from the utter complexity of modern things. It's barely more complicated than a programmable calculator. Certainly simpler, cleaner, and arguably more powerful than svg graphics.

You don't even need to read any manual to guess what this example program does:

   100 100 moveto 
   200 300 lineto
   stroke
> Far from the utter complexity of modern things.

Although it would, at times, go wrong there are very few things to this day that do impress me more than typing this (admire my "useless use of cat" btw):

    ... $   cat tiger.ps | netcat 192.168.0.78 9100
And see my HP LaserJet 4M+ (speaking PostScript natively) start printing.

Yeah, yeah, yeah, I do have a SOHO and a modern printer/scanner at home and it can do more stuff.

But the elegance of netcat'ing a PostScript file to a printer and seeing it print without needing any driver nor any configuration whatsoever [1] was quite something.

It was simpler indeed and it was elegant and it did feel like magic.

Now it wasn't fun if you printed many pages and suddenly it started printing garbage but still...

[1] you had to configure the printer itself to get an IP, but that was done on the printer itself

It is truly awesome. I never get tired of this trick.
I’d most certainly need to read a manual to know what this does.

Is there an implicit bounding box? How large is it? Does x or y go first in the parameters?

> Certainly simpler, cleaner, and arguably more powerful than svg graphics.

Much more powerful, I agree. Some might even say a bit too powerful for a graphics description language, halting problem and all.

PostScript's magic is subtle. I once tried writing a PostScript interpreter in ADA. Got far enough to display the turkey example and realized that PostScript code can modify itself and decided I didn't want to go there.
I have absolutely no idea what that program is intending to do, such that I can’t tell if you’re joking.
Your guess is as good as mine, but I assume it draws a line from coordinates (100, 100) to (200, 300)
It draws a straight line.
x coord, y coord, command that consumes the arguments from what we can infer is pushed onto a stack beforehand
The drawing part is pretty straightforward. It’s the stack-based approach and reverse Polish notation thing that trips me off.

Very cool stuff, but not what I do day to day, so it’s a bit intimidating at first.

If you want an accessible introduction to postscript that does a bunch of very pretty pictures you can't go wrong with: https://personal.math.ubc.ca/~cass/graphics/text/www/

I particularly like chapter 14 where you implement 3d shader in postscript.

I've done a bit of PostScript programming in the dim and distant past - the most ambitious of which was a "pretty-printer" for the YAM email client on Amiga, which otherwise just printed emails as plain ASCII.

I found PostScript to be one of those things where something "clicks" after a while, and I really started to appreciate the elegance and simplicity. The hardest part is the mental gymnastics required to track what's on the stack and in what order!

OP here. Indeed, hardest part is the initial mental gymnastics. This can be overcome by devising and enforcing some conventions that I wrote about in a separate article https://seriot.ch/projects/programming_in_postscript.html
It's not a terrible language; it just requires a little different thinking. In 1988/89, I learned to write a postscript generator with no dev environment, just reams of paper. Debugging was hard since you had to add debugging print statements in the same document you were printing, which was hard if no printing occurred! I read Adobe Illustrator files, which were the precursor to PDF, so at least I had something to look at.