Programming in PostScript - Computerphile

Sdílet
Vložit
  • čas přidán 10. 04. 2014
  • 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

Komentáře • 203

  • @TheMasonX23
    @TheMasonX23 Před 7 lety +219

    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
    @mountainhobo Před 10 lety +61

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

  • @PointB1ank
    @PointB1ank Před 8 lety +243

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

  • @erajoj
    @erajoj Před 10 lety +27

    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.

  • @TimTeatro
    @TimTeatro Před 10 lety +38

    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.

  • @PeterWalkerHP16c
    @PeterWalkerHP16c Před 8 lety +158

    Someone should invent a postfix language called 'Yoda'.

  • @DaveScottAggie
    @DaveScottAggie Před 8 lety +19

    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.

  • @ThisNameIsVeryClever
    @ThisNameIsVeryClever Před 10 lety +18

    This man should narrate everything.

  • @GegoXaren
    @GegoXaren Před 10 lety +189

    And suddenly TeX does not seems so bad...

    • @JelmerBorst
      @JelmerBorst Před 10 lety +26

      has not ever been bad ;-)

    • @ZardoDhieldor
      @ZardoDhieldor Před 10 lety +14

      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 Před 10 lety +7

      ***** 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 Před 10 lety +3

      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 Před 10 lety +3

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

  • @duncancarr7822
    @duncancarr7822 Před 10 lety +14

    "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

  • @Bixbeat
    @Bixbeat Před 6 lety +1

    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.

  • @DudokX
    @DudokX Před 10 lety +6

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

  • @JavierRuizGonzalez
    @JavierRuizGonzalez Před 10 lety +9

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

  • @LeethLee1
    @LeethLee1 Před 5 lety +1

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

  • @nrviognjiocfmbkirdom
    @nrviognjiocfmbkirdom Před 10 lety +3

    Computerphile just gets better and better.

  • @sanderd17
    @sanderd17 Před 8 lety +24

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

  • @GeneralPotatoSalad
    @GeneralPotatoSalad Před 10 lety +5

    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.

  • @stumbling
    @stumbling Před 9 lety +41

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

  • @AndreiHognogi
    @AndreiHognogi Před 10 lety +1

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

  • @f.eckert
    @f.eckert Před 10 lety +2

    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.

  •  Před 10 lety +2

    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.

  • @jasondoe2596
    @jasondoe2596 Před 10 lety +1

    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.

  • @jmp01a24
    @jmp01a24 Před 7 lety +14

    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.

  • @darkmage07070777
    @darkmage07070777 Před 10 lety +2

    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
    @dimitrioskalfakis Před 8 lety +4

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

  • @f0rthleo
    @f0rthleo Před 10 lety +4

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

  • @PontusWelin
    @PontusWelin Před 10 lety +6

    Postfix is so elegant. I love it!

  • @MatthewHolevinski
    @MatthewHolevinski Před 9 lety +10

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

  • @TheSidyoshi
    @TheSidyoshi Před 10 lety +4

    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.

  • @UnionYes1021
    @UnionYes1021 Před 11 měsíci

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

  • @JohnCorrigan
    @JohnCorrigan Před 10 lety

    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.

  • @DanielBeecham
    @DanielBeecham Před 10 lety +7

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

    • @kaitlyn__L
      @kaitlyn__L Před 10 lety +5

      or "the relaxing guy" :3

    • @justahker3988
      @justahker3988 Před 10 lety +1

      "The typesetting guy" would be slightly more accurate.

    • @kaitlyn__L
      @kaitlyn__L Před 10 lety

      well, he explained the history of error correction first!

  • @NikolajLepka
    @NikolajLepka Před 10 lety +79

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

  • @stedebonnet3151
    @stedebonnet3151 Před 8 lety +15

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

  • @LostTimeLady
    @LostTimeLady Před 10 lety +3

    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!

  • @Westkane11
    @Westkane11 Před 8 lety +11

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

  • @ButzPunk
    @ButzPunk Před 10 lety +2

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

  • @dedu15
    @dedu15 Před 10 lety

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

  • @frognik79
    @frognik79 Před 10 lety +3

    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?

  • @runnerelf
    @runnerelf Před 10 lety +4

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

  • @duncancarr7822
    @duncancarr7822 Před 10 lety

    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

  • @Kabitu1
    @Kabitu1 Před 10 lety +9

    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.

  • @alcesmir
    @alcesmir Před 10 lety +8

    ***** 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!

  • @lohphat
    @lohphat Před 10 lety +1

    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.

  • @rainmain
    @rainmain Před 10 lety +20

    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 ?

  • @redbaron-jh9kw
    @redbaron-jh9kw Před 8 lety +3

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

  • @sbusweb
    @sbusweb Před 8 lety +4

    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?

  • @Nilguiri
    @Nilguiri Před 10 lety

    ¡Fantástico! Gracias chicos.

  • @AndyBlair
    @AndyBlair Před 10 lety

    This is old school! Very nice :D

  • @razorborne
    @razorborne Před 10 lety +1

    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?

  • @luvjazz
    @luvjazz Před 8 lety

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

  • @matrinGD
    @matrinGD Před 10 lety +3

    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.

  • @GellyGelbertson
    @GellyGelbertson Před 10 lety

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

  • @GordonPhillips
    @GordonPhillips Před 5 lety

    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

  • @kujmous
    @kujmous Před 10 lety

    Loved this!!!!

  • @RealDealHolyfield2099
    @RealDealHolyfield2099 Před 10 lety

    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
    @SahilChaturvedi Před 10 lety

    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?

  • @Jeff121456
    @Jeff121456 Před 8 lety +2

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

  • @flydiscovery
    @flydiscovery Před 10 lety

    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?

  • @madamerosario
    @madamerosario Před 10 lety +10

    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 Před 10 lety +1

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

  • @salaufer
    @salaufer Před 10 lety +3

    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.

  • @socearo
    @socearo Před 10 lety

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

  • @therealEmpyre
    @therealEmpyre Před 10 lety

    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.

  • @u.l.robotics7003
    @u.l.robotics7003 Před 10 lety +1

    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?

  • @SumeaBizarro
    @SumeaBizarro Před 8 lety +2

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

  • @frankharr9466
    @frankharr9466 Před 8 lety +5

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

  • @JulianOnions
    @JulianOnions Před 10 lety

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

  • @blmutantx
    @blmutantx Před 10 lety

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

  • @GeorgeChoy
    @GeorgeChoy Před 7 lety

    thank you, that was awesome

  • @5lammer
    @5lammer Před 10 lety +20

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

    • @5lammer
      @5lammer Před 10 lety +17

      not really, just considering < is and open just like a (, i feel the need to close it, that's all.)>

    • @Niosus
      @Niosus Před 10 lety +18

      Sam Smith (Poor you

    • @ze_rubenator
      @ze_rubenator Před 10 lety +29

      Niosus I hate it when people end in the middle of

    • @aphilra
      @aphilra Před 10 lety +5

      Detecting a little bit of OCD here ;D

    • @daisukekichigoru4900
      @daisukekichigoru4900 Před 10 lety +5

      IT'S CDO!!!

  • @smanzoli
    @smanzoli Před 5 lety

    Loved programming my HP48 in RPN

  • @anothermoth
    @anothermoth Před 10 lety +1

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

  • @juangreen8194
    @juangreen8194 Před 10 lety +8

    as a programmer I find this very interesting

  • @15kalas15
    @15kalas15 Před 10 lety

    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?

  • @JunJiePang
    @JunJiePang Před 10 lety +1

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

    • @GegoXaren
      @GegoXaren Před 10 lety +1

      Not a DVD, it is a binder.

  • @GeekIWG
    @GeekIWG Před 10 lety +3

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

    • @RealDealHolyfield2099
      @RealDealHolyfield2099 Před 10 lety

      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.

  • @pbezunartea
    @pbezunartea Před 10 lety

    nice video!

  • @DaveScottAggie
    @DaveScottAggie Před 8 lety +2

    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?

  • @hakarthemage
    @hakarthemage Před 10 lety +1

    I'd like to see some stuff about assembly

  • @thomasvarney723
    @thomasvarney723 Před 10 lety

    Which distro/DE was the professor using?

    • @kaitlyn__L
      @kaitlyn__L Před 10 lety

      elsewhere in the comments says opensuse!

  • @TheSuperkiko98
    @TheSuperkiko98 Před 10 lety

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

  • @duncancarr7822
    @duncancarr7822 Před 10 lety

    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

  • @ybra
    @ybra Před 10 lety +1

    This is very interesting BANG

  • @filippe999
    @filippe999 Před 10 lety

    are thse your professor from computer science course?

  • @nosepickerextreme
    @nosepickerextreme Před 9 lety

    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.

  • @whackediw
    @whackediw Před 10 lety

    Can you explain how computer gets data from hard drive ?

  • @HadronJack
    @HadronJack Před 10 lety

    Good stuff indeed.

  • @sereda008
    @sereda008 Před 10 lety +8

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

  • @Deh9o11en8or
    @Deh9o11en8or Před 10 lety +4

    can you please talk about something other than postscript

  • @wisteela
    @wisteela Před 9 lety +7

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

  • @sjheiss
    @sjheiss Před 10 lety

    Can you make graphical games in PostScript?

  • @flapjacksmike
    @flapjacksmike Před 10 lety

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

    • @Turidus
      @Turidus Před 10 lety

      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.

  • @xaviripo
    @xaviripo Před 10 lety +2

    When you write comments in the middle of a video, instead of "< the 'j' in jam! >" you should write "".

  • @whackediw
    @whackediw Před 10 lety

    Can you show how computer gets data from hard drive?

  • @PaulaJBean
    @PaulaJBean Před 7 lety

    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.

  • @ghollisjr
    @ghollisjr Před 10 lety

    Sitting here, sipping my coffee, watching this vid whilst my compiled data analysis code in Common Lisp cranks through some data when I hear "Lisp is interpreted..."

  • @datguyoverdere6616
    @datguyoverdere6616 Před 4 lety

    this dood is da bess

  • @antizubar
    @antizubar Před 10 lety

    Please talk more about algorithms :)

  • @Portablesounds
    @Portablesounds Před 10 lety +1

    :DDD Is that little bear on your desk wearing a Raspberry Pi tshirt?

  • @allhaillukeywes
    @allhaillukeywes Před 9 lety +5

    why on earth would you want to bother with the stack in a scripting language?