Programming in PostScript - Computerphile

Audible free book: www.audible.com/computerphile
PostScript is more than just a 2D graphics language, it's a fully operational programming language - Professor Brailsford explains how it works.
Reverse Polish Notation and the Stack: • Reverse Polish Notatio...
At 7min 15seconds the Professor refers to for as being the 'operand' when he meant the 'operator'.
The Professor's PS Program: bit.ly/postscriptprog
/ computerphile
/ computer_phile
This video was filmed and edited by Sean Riley.
Computer Science at the University of Nottingham: bit.ly/nottscomputer
Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: bit.ly/bradychannels

Пікірлер: 203

  • @TheMasonX23
    @TheMasonX237 жыл бұрын

    I love Professor Brailsford's videos; he explains things in a very understandable manner and has a knack for anticipating possible questions and misconceptions.

  • @mountainhobo
    @mountainhobo10 жыл бұрын

    I love Professor Brailsford's presentation style. Pity I never had teachers like that.

  • @TimTeatro
    @TimTeatro10 жыл бұрын

    Thanks for the video, Professor. For anyone trying the tutorial, it is useful to include the command showpage at the bottom of the script to get your page drawn! You'll not see much otherwise.

  • @erajoj
    @erajoj10 жыл бұрын

    I used to love "programming" in PS in the early nineties. Had excellent reference books from Adobe. Even wrote a ray-tracer for a DEC laser printer. Took an entire day to get the results.

  • @PointB1ank
    @PointB1ank8 жыл бұрын

    This guy is who I want to be when I'm older.

  • @DaveScottAggie
    @DaveScottAggie8 жыл бұрын

    I enjoy your computer history lessons. Some of your stories brings memories that I can remember seeing that type of equipment. My father worked in data processing for banks since the 1960's. Sometimes I would go to the office with him and see the machines at work. Then when I was in the US Navy, the computers were core memory, and loading programs with the half inch mag tape on reel to reel. They did not necessarily want the most cutting edge computers onboard a combat ship, because it needed to be proven technology and had to be made and tested to withstand the harsh conditions that could occur in that environment.

  • @GegoXaren
    @GegoXaren10 жыл бұрын

    And suddenly TeX does not seems so bad...

  • @JelmerBorst

    @JelmerBorst

    10 жыл бұрын

    has not ever been bad ;-)

  • @ZardoDhieldor

    @ZardoDhieldor

    10 жыл бұрын

    I think TeX is great for documents, but PostScript seems to be more powerful. If I want to insert a graph in a LaTeX maths document I use PS graphics. LaTeX couldn't do graphs itself.

  • @JelmerBorst

    @JelmerBorst

    10 жыл бұрын

    ***** start off with a template, an easy compiler such as sharelatex.com and some Google. The more you use, the easier it becomes

  • @TheAaaargh

    @TheAaaargh

    10 жыл бұрын

    Zardo Schneckmag GNUplot, a powerful plotting program, can export straight to LaTex. All you have to do in your .tex file is to then \include{graphFile.tex} where you wnat the graph to be. :)

  • @alcesmir

    @alcesmir

    10 жыл бұрын

    Zardo Schneckmag LaTeX can do graphs and graphics by itself! Check out the pgfplots and TikZ packages.

  • @ThisNameIsVeryClever
    @ThisNameIsVeryClever10 жыл бұрын

    This man should narrate everything.

  • @Bixbeat
    @Bixbeat6 жыл бұрын

    These series are fantastic. As someone using higher-order programming languages but never having done a theoretical CompSci course I really appreciate the diversity, pacing, and level of depth of these videos. Fantastic job to everyone involved.

  • @sanderd17
    @sanderd178 жыл бұрын

    Using the standard mathematical signs for the axis, don't see that often in a programming language.

  • @PeterWalkerHP16c
    @PeterWalkerHP16c8 жыл бұрын

    Someone should invent a postfix language called 'Yoda'.

  • @JavierRuizGonzalez
    @JavierRuizGonzalez10 жыл бұрын

    Nice video, professor. Postscript is still used, for exporting high quality graphics files and many professional programs (for example for music engraving) let you print to a PS file... Great to further tweaking...

  • @duncancarr7822
    @duncancarr782210 жыл бұрын

    "Postscript" is a resolution-independent, page description language It underpins all DTP (Desktop Publishing) & pre-press software, including Adobe InDesign, Illustrator, QuarkXPress, etc. etc. etc. If you create PDF's then you'll be using it without realising so

  • @DudokX
    @DudokX10 жыл бұрын

    What a nice time to post new Computerphile video! I can eat lunch while I watch.

  • 10 жыл бұрын

    I've seen some fairly complex and computationally intensive programs written in postscript. My brother showed me a project of his, at Lisbon U, doing a genetic selection algorithm for composite materials. That was about 15 years ago and I was just a child back then. I didn't understand much of the programming side but it stuck with me how versatile postscript can be. It was also probably the first time i've seen genetic algorithms in action. Another direct application of postscript programming: all graphics in his published papers were done in postscript. The papers were written in TeX and TeX allows embedding postscript graphics. You can write the postscript bits by hand, which means you can create graphics that do live computations, and that is very useful especially if you're writing math proofs.

  • @nrviognjiocfmbkirdom
    @nrviognjiocfmbkirdom10 жыл бұрын

    Computerphile just gets better and better.

  • @GeneralPotatoSalad
    @GeneralPotatoSalad10 жыл бұрын

    Of all the people on Computerphile, Professor Brailsford is the only one whose videos require me to consult the Jargon File on a regular basis. And it's awesome. bang: n. Common spoken name for ! (ASCII 0100001), especially when used in pronouncing a bang path in spoken hackish. In elder days this was considered a CMUish usage, with MIT and Stanford hackers preferring excl or shriek; but the spread of Unix has carried ‘bang’ with it (esp. via the term bang path) and it is now certainly the most common spoken name for !. Note that it is used exclusively for non-emphatic written !; one would not say “Congratulations bang” (except possibly for humorous purposes), but if one wanted to specify the exact characters “foo!” one would speak “Eff oh oh bang”. See shriek, ASCII.

  • @jmp01a24
    @jmp01a247 жыл бұрын

    Can you PLEASE do a video on FORTH and also some of it's version history. And a follow up video with some FORTH programming? Thanks. I do like your videos a lot.

  • @f.eckert
    @f.eckert10 жыл бұрын

    Thanks, this video brought back memories. I did some PostScript programming for fun back in 1989 or 1990 in an editor called LSE on a VT220 terminal connected to a microVAX and a DEC laser printer.

  • @stumbling
    @stumbling9 жыл бұрын

    Interesting. Any possibility of getting some TeX / LaTeX videos?

  • @LeethLee1
    @LeethLee15 жыл бұрын

    I don't want the videos to stop. I'm learning way too much right now haha. Thanks so much for the great resources!

  • @lohphat
    @lohphat10 жыл бұрын

    Doesn't the mul operator pop the 100 and the loop counter off the stack and replace it with the product? What happens with the next loop iteration? Answer: the curly braces protect the stack so that the loop value is preserved for the next iteration.

  • @AndreiHognogi
    @AndreiHognogi10 жыл бұрын

    This is awesome. I had no idea what postscript was, but this makes perfect sense to me. Thank you Computerphile.

  • @jasondoe2596
    @jasondoe259610 жыл бұрын

    One of the most interesting videos on the channel, among many amazing ones. Interesting even for us who are supposed to know such stuff, but belong to a younger generation. Professor Brailsford is always a joy to watch. This video definitely needs a follow-up (and preferable several ones!) - you got me interested in stack-based languages :-) P.S. Of course Linux is better for programming - I'd even argue that Unix-like OSes are better for everything.

  • @darkmage07070777
    @darkmage0707077710 жыл бұрын

    Wow, I actually understand this now. I feel like I have a slightly better grasp on pointer position and stack pushing. Nicely done; I wouldn't mind more of these!

  • @dimitrioskalfakis
    @dimitrioskalfakis8 жыл бұрын

    another great video with Dr. Brailsford. born to teach.

  • @DanielBeecham
    @DanielBeecham10 жыл бұрын

    Don't worry, Brailsford, I never saw you as "the history guy". I see you as "the text guy".

  • @kaitlyn__L

    @kaitlyn__L

    10 жыл бұрын

    or "the relaxing guy" :3

  • @justahker3988

    @justahker3988

    10 жыл бұрын

    "The typesetting guy" would be slightly more accurate.

  • @kaitlyn__L

    @kaitlyn__L

    10 жыл бұрын

    well, he explained the history of error correction first!

  • @JohnCorrigan
    @JohnCorrigan10 жыл бұрын

    I loved this video. Great to see stack languages get a bit of focus. You could probably do a whole series of videos on postscript: defining new operators and the concatenative nature of the language. I'd be very interested in that. Also from the looks of things in the comments, a video on programming paradigms would be very interesting to people.

  • @PontusWelin
    @PontusWelin10 жыл бұрын

    Postfix is so elegant. I love it!

  • @f0rthleo
    @f0rthleo10 жыл бұрын

    Lovely to hear about another stack based language, this really reminds me of the days when I was starting out whith Forth Thanks allot!

  • @Westkane11
    @Westkane118 жыл бұрын

    Very nice explanation. This PostScript language is difficult to read because of all the implicitly expressions in it.

  • @TheSidyoshi
    @TheSidyoshi10 жыл бұрын

    I love reverse polish notation, it's a little weird at first, but the advantage is that you can describe data flow in a very concise form. So: In C or Java, you'd write a "square" function like this: int square( int x ) { return x * x; } In a postfix language you could probably get away with something like (not sure if this works in Postscript): /square { dup * } def The above pseudo-code means: duplicate the item on the stack and then multiply. It might not seem like it, but the latter is much more computer friendly. Translating the second program is very easy. The C/Java program would require several passes to generate the machine code. One problem is that the system has to try and remember the call signature while reading the code, so if I called square: square("hello"); This would give an error, because "hello" is not an integer. The machine has to remember that square only accepts integers, where as, in the reverse polish notation, it has already read or generated all the parameters before the function is called, so: "hello" square When the machine sees the square function and tries to execute it, the string "hello" will be on top of the stack. When running the square function, it will try to multiply two strings, and yield an error. It doesn't have to figure out the order or operations or a complex set of nested function calls. It can simply read and execute and halt at the first error. Simple but effective. The above was a simple example, but for more complex statements things quickly get difficult in C/Java style. Here, postfix starts to shine. Example: C/Java: square( squareRoot( 2 ^ 10 )); Postfix: 2 10 ^ squareRoot square Another cool thing here is that functions can be spliced, so looking at the last few symbols, we could define a function with: /myFunc { 10 ^ squareRoot square } def myFunc takes a number and raises it to the power 10, then takes the squareRoot, then squares it, and returns the result. You can cut/paste a sequence of symbols, and replace with a single symbol.

  • @MatthewHolevinski
    @MatthewHolevinski9 жыл бұрын

    I like how the Apple monitor is turned around to face the wall, like it's in Timeout!

  • @frankharr9466
    @frankharr94668 жыл бұрын

    I'm rather surprised. I'd have expected 0,0 to be the top left corner, not the bottom left.

  • @NikolajLepka
    @NikolajLepka10 жыл бұрын

    I see OpenSuse on the screen, the professor is a linux user :D

  • @ButzPunk
    @ButzPunk10 жыл бұрын

    Awesome! This makes me wanna see you do something on TeX or maybe LaTeX or one of the other ones.

  • @alcesmir
    @alcesmir10 жыл бұрын

    ***** You should really include a link to the source file in the video description. It's not too bad in this video, but if you venture on to a bit longer code snippets you really should do it. Other than that, I'm very glad to see some actual programming on here!

  • @possiblydavid

    @possiblydavid

    10 жыл бұрын

    It actually is in the description now.

  • @dedu15
    @dedu1510 жыл бұрын

    very good and informative, I'd like to see more videos like this!

  • @UnionYes1021
    @UnionYes1021 Жыл бұрын

    Thank you Professor! Loved watching this. Great teaching style.

  • @runnerelf
    @runnerelf10 жыл бұрын

    When the for-loop counter is multiplied by 100, doesn't the result replace the original loop counter in the stack?

  • @duncancarr7822
    @duncancarr782210 жыл бұрын

    Try the example below, changing the "/maxdepth 1 def" to other values & see the fractal pattern become more & more complex as the iterations are increased (if I go above 13 my computer takes a while to render the (extremely) complex image) This example really shows the power of this language

  • @LostTimeLady
    @LostTimeLady10 жыл бұрын

    That moment when you smile a wry smile as you realise that you've actually programmed with ghostscipt and ghostview before! Wow, the programming I've done actually can be adapted. Yay!

  • @stedebonnet3151
    @stedebonnet31518 жыл бұрын

    "both for Linux and Mac and PC" - I like it! ☺ Seems like they switched to Qubits already!

  • @rainmain
    @rainmain10 жыл бұрын

    For someone who's only used languages using PreScript notation this is extremely confusing. I don't see why this type of notation would be useful. Can someone elaborate on that please ?

  • @matrinGD
    @matrinGD10 жыл бұрын

    Followed this on KDE with kate and Ocular. I had to add the command "showpage" at the end of the script to produce visible text.

  • @Kabitu1
    @Kabitu110 жыл бұрын

    Why on earth would they make the coordinate system start in the lower left corner and run up the page? Text runs down the page.

  • @frognik79
    @frognik7910 жыл бұрын

    Why doesn't this corrupt the stack? If the loop counter is popped off the stack by mul and replaced by the answer how does the loop know the correct number to increment for the next loop? Is the loop count stored somewhere else but also pushed to the stack?

  • @sbusweb
    @sbusweb8 жыл бұрын

    Hrrm, have you not screwed up the stack -- the loop counter is now lost and the stack is one level higher than it was? -- maybe the postscript interpretation of end-of-loop always re-normalizes the stack position and actually stores the loop count elsewhere, or similar?

  • @GordonPhillips
    @GordonPhillips5 жыл бұрын

    I remember Push and pop stack handling! used it in BAL. Never was much good at it, guess it's because I was drunk most of the time, but this was a great poke to the remember button. Thank you

  • @AndyBlair
    @AndyBlair10 жыл бұрын

    This is old school! Very nice :D

  • @Nilguiri
    @Nilguiri10 жыл бұрын

    ¡Fantástico! Gracias chicos.

  • @redbaron-jh9kw
    @redbaron-jh9kw8 жыл бұрын

    So then the loop counter value that is on the stack is basically a copy of the same value stored somewhere else?

  • @Jeff121456
    @Jeff1214568 жыл бұрын

    In 92 I created a ps program to print forms that flows data across pages differently in each section long before wysiwg databases.

  • @madamerosario
    @madamerosario10 жыл бұрын

    If you haven't already done so, a video on types, typed vs. untyped languages and compiled vs. interpreted languages would be helpful for intuition. strings, characters, numbers, structs, objects, references, data structures and algorithms ... I think it would be fun :)

  • @Christophe_L

    @Christophe_L

    10 жыл бұрын

    I agree! Categorization of languages is a topic that isn't discussed very much in the classroom, and is usually left for Computer Scientists.

  • @razorborne
    @razorborne10 жыл бұрын

    is there a reason you had to define n=6 and then reference n, instead of just referencing 6 directly? or was that just to show how defining variables worked? would a for loop with parameters 1 1 6 not work?

  • @kujmous
    @kujmous10 жыл бұрын

    Loved this!!!!

  • @nosepickerextreme
    @nosepickerextreme9 жыл бұрын

    The most amazing thing with Postscript is the ability to redefine operators. I am probably wrong, but I do not think you can redefine basic operations in most programming languages. For example, can you redefine "+" in C? I do not know of any other language that you can do the following: (keep in mind a == just shows you a result). -------- Program: 5 3 add == ------ Result 8 ----- Program %!PS /add { systemdict /add get exec 1 systemdict /add get exec } def 5 3 add == ------ Result 9 Now anytime you use add in the program after the statement above, it will not add properly. This may seem useless, but you would be amazed on what you can do with the above and modify a printers behavior.

  • @duncancarr7822
    @duncancarr782210 жыл бұрын

    If you are on a Mac, simply save the document as a TEXT file (NOT MS-Word, for example) & drag & drop onto "Preview" ... this will render the Postscript

  • @salaufer
    @salaufer10 жыл бұрын

    writing non-trivial programs in postscript is a nightmare. there are a lot of things it can't do (e.g. sockets, unbuffered reads), since it has no facility for system calls. it's a lot easier if you make liberal use of dictionaries, and get a good understanding of how it handles references, but it's still not much use as a general-purpose language. it's an interesting challenge though.

  • @JulianOnions
    @JulianOnions10 жыл бұрын

    I recall Brian Reid writing the DECwrl logo in postscript using all manner of tricks to get it to look right!

  • @anothermoth
    @anothermoth10 жыл бұрын

    I remember running into a paper on fractals that used postscript to generate all it's illustrations...

  • @SumeaBizarro
    @SumeaBizarro8 жыл бұрын

    Funny enough I had my first time learning people call exclamation mark "Bang" through a music game In The Groove 2 which had a music track in it that was named modernly enough, just "!" - some people addressed it as "Bang by so and so" and I was like "But it is exclamation mark... no?"

  • @GellyGelbertson
    @GellyGelbertson10 жыл бұрын

    When the increment counter on the top of the stack is removed, does it get replaced somehow? How does that work?

  • @smanzoli
    @smanzoli5 жыл бұрын

    Loved programming my HP48 in RPN

  • @luvjazz
    @luvjazz8 жыл бұрын

    +1 for bang! Never heard of "shriek" before. Is that common in the UK?

  • @GeekIWG
    @GeekIWG10 жыл бұрын

    Interesting. I never knew that postscript was an actual programming language. I always thought it was just a document format.

  • @RealDealHolyfield2099

    @RealDealHolyfield2099

    10 жыл бұрын

    Me too. I used to used a Postscript printer called Postscript Level II to export Autocad drawings to other graphic programs. I never thought about the underlying code.

  • @RealDealHolyfield2099
    @RealDealHolyfield209910 жыл бұрын

    Question from US: Since A4 size paper is metric based, is it ever confusing the fonts are measured in dots per inch? I never realized the inch units are also part of the programming language.

  • @SahilChaturvedi
    @SahilChaturvedi10 жыл бұрын

    For the exch operator, what if there's more than two operands? Will it just flip the order of all of them on the stack?

  • @DaveScottAggie
    @DaveScottAggie8 жыл бұрын

    So now I know what it means when I print something to the PostScript printer and get a stack overflow. I guess to many things were on the stack, and information got lost?

  • @GeorgeChoy
    @GeorgeChoy7 жыл бұрын

    thank you, that was awesome

  • @u.l.robotics7003
    @u.l.robotics700310 жыл бұрын

    If the "mul" Operator takes the for-counter out of the stack, how does the programm know what the count is for the next round?

  • @5lammer
    @5lammer10 жыл бұрын

    it's really bothering me that his omputerphile> is not enclosed. how bout or

  • @5lammer

    @5lammer

    10 жыл бұрын

    not really, just considering

  • @Niosus

    @Niosus

    10 жыл бұрын

    Sam Smith (Poor you

  • @ze_rubenator

    @ze_rubenator

    10 жыл бұрын

    Niosus I hate it when people end in the middle of

  • @aphilra

    @aphilra

    10 жыл бұрын

    Detecting a little bit of OCD here ;D

  • @daisukekichigoru4900

    @daisukekichigoru4900

    10 жыл бұрын

    IT'S CDO!!!

  • @hakarthemage
    @hakarthemage10 жыл бұрын

    I'd like to see some stuff about assembly

  • @flydiscovery
    @flydiscovery10 жыл бұрын

    So, if RPN languages are strictly LIFO on the stack, how is it possible for my HP48 to scroll through and pick values out of the stack?

  • @socearo
    @socearo10 жыл бұрын

    What if you want to use /n multiple times? what's the function for that?

  • @PaulaJBean
    @PaulaJBean7 жыл бұрын

    A small remark. Python is not an interpreted language: it's compiled to bytecode, which is then executed in a virtual machine, just like Java, C#, and a lot of other languages.

  • @juangreen8194
    @juangreen819410 жыл бұрын

    as a programmer I find this very interesting

  • @blmutantx
    @blmutantx10 жыл бұрын

    Can you talk about LaTeX as well at a later stage?

  • @therealEmpyre
    @therealEmpyre10 жыл бұрын

    I don't understand. Wouldn't popping the for loop's counter off of the stack break the for loop? The second time through the loop, the for command would try to pop the current value of the counter only to find that it isn't there, having been popped earlier.

  • @15kalas15
    @15kalas1510 жыл бұрын

    Why doesn't postscript use the coordinate system where 0,0 is the upper-left corner of the paper. AFAIK this coordinate system was developed for TVs and was ported for a lot of use in computers because it is very intuitive for how we read documents and create them in our heads. It is less intuitive maybe for those who have done lots of paper math but it is much easier to work with if you are trying to make something readable and seems like it would be a perfect fit for postscript. Is there something I am missing or is this something that has been covered before?

  • @TheSuperkiko98
    @TheSuperkiko9810 жыл бұрын

    Make a video on the OSI Model, please!!!

  • @JunJiePang
    @JunJiePang10 жыл бұрын

    Is that a "Buffy the vampire slayer" DVD in the background beside the monitor ?

  • @GegoXaren

    @GegoXaren

    10 жыл бұрын

    Not a DVD, it is a binder.

  • @pbezunartea
    @pbezunartea10 жыл бұрын

    nice video!

  • @Deh9o11en8or
    @Deh9o11en8or10 жыл бұрын

    can you please talk about something other than postscript

  • @HadronJack
    @HadronJack10 жыл бұрын

    Good stuff indeed.

  • @wisteela
    @wisteela9 жыл бұрын

    Who else has seen what happens if you send PS to an old HP LaserJet without the PS cartridge being in? :-)

  • @ybra
    @ybra10 жыл бұрын

    This is very interesting BANG

  • @whackediw
    @whackediw10 жыл бұрын

    Can you explain how computer gets data from hard drive ?

  • @xaviripo
    @xaviripo10 жыл бұрын

    When you write comments in the middle of a video, instead of " " you should write "".

  • @thomasvarney723
    @thomasvarney72310 жыл бұрын

    Which distro/DE was the professor using?

  • @kaitlyn__L

    @kaitlyn__L

    10 жыл бұрын

    elsewhere in the comments says opensuse!

  • @sjheiss
    @sjheiss10 жыл бұрын

    Can you make graphical games in PostScript?

  • @antizubar
    @antizubar10 жыл бұрын

    Please talk more about algorithms :)

  • @sereda008
    @sereda00810 жыл бұрын

    I love how this is one of the few files that actually assumes you have a brain, and teaches you something ^_^

  • @prwchan
    @prwchan10 ай бұрын

    Lisp has not been only an interpreted language for a very long time.

  • @filippe999
    @filippe99910 жыл бұрын

    are thse your professor from computer science course?

  • @whackediw
    @whackediw10 жыл бұрын

    Can you show how computer gets data from hard drive?

  • @flapjacksmike
    @flapjacksmike10 жыл бұрын

    So why not "10 100 mul moveto"? Would that work too without the exchange?

  • @Turidus

    @Turidus

    10 жыл бұрын

    i dont think so, i think you would get" x 1000 moveto". 10 and 100 would multilply, giving you 1000, and moveto would take the 1000 and the number of loops as argument. at least if it executes mul for moveto.

  • @blenderpanzi
    @blenderpanzi10 жыл бұрын

    "It's easy to get software for both Linux, Mac and for PC [...]" Both? So, does this mean it is easy to get PostScript software for Mac based Linux distributions and and for PC based Linux distributions? What about ARM?

  • @boblake2340

    @boblake2340

    10 жыл бұрын

    I just installed gv on a raspberrypi, which uses the ARM processor. It works :)

  • @hunakosdem
    @hunakosdem10 жыл бұрын

    Upvoted, but will break your fingers for the defocuses sooner or later.

  • @robertm4757
    @robertm47576 жыл бұрын

    Also very entertaining