Programming in PostScript - Computerphile

Поделиться
HTML-код
  • Опубликовано: 10 апр 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

Комментарии • 203

  • @TheMasonX23
    @TheMasonX23 8 лет назад +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 10 лет назад +62

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

  • @TimTeatro
    @TimTeatro 10 лет назад +39

    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
    @erajoj 10 лет назад +30

    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
    @PointB1ank 8 лет назад +243

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

  • @DaveScottAggie
    @DaveScottAggie 8 лет назад +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 10 лет назад +18

    This man should narrate everything.

  • @JavierRuizGonzalez
    @JavierRuizGonzalez 10 лет назад +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...

  • @Bixbeat
    @Bixbeat 6 лет назад +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.

  • @PeterWalkerHP16c
    @PeterWalkerHP16c 8 лет назад +158

    Someone should invent a postfix language called 'Yoda'.

  • @DudokX
    @DudokX 10 лет назад +6

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

  • @duncancarr7822
    @duncancarr7822 10 лет назад +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

  • @GeneralPotatoSalad
    @GeneralPotatoSalad 10 лет назад +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.

  • @nrviognjiocfmbkirdom
    @nrviognjiocfmbkirdom 10 лет назад +3

    Computerphile just gets better and better.

  •  10 лет назад +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.

  • @sanderd17
    @sanderd17 8 лет назад +24

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

  • @GegoXaren
    @GegoXaren 10 лет назад +190

    And suddenly TeX does not seems so bad...

    • @JelmerBorst
      @JelmerBorst 10 лет назад +26

      has not ever been bad ;-)

    • @ZardoDhieldor
      @ZardoDhieldor 10 лет назад +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 10 лет назад +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 10 лет назад +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 10 лет назад +3

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

  • @f.eckert
    @f.eckert 10 лет назад +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.

  • @LeethLee1
    @LeethLee1 5 лет назад +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!

  • @jmp01a24
    @jmp01a24 7 лет назад +15

    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.

  • @AndreiHognogi
    @AndreiHognogi 10 лет назад +1

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

  • @stumbling
    @stumbling 9 лет назад +41

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

  • @jasondoe2596
    @jasondoe2596 10 лет назад +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.

  • @darkmage07070777
    @darkmage07070777 10 лет назад +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 8 лет назад +4

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

  • @JohnCorrigan
    @JohnCorrigan 10 лет назад

    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.

  • @MatthewHolevinski
    @MatthewHolevinski 10 лет назад +10

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

  • @f0rthleo
    @f0rthleo 10 лет назад +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!

  • @lohphat
    @lohphat 10 лет назад +2

    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.

  • @Westkane11
    @Westkane11 8 лет назад +11

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

  • @PontusWelin
    @PontusWelin 10 лет назад +6

    Postfix is so elegant. I love it!

  • @LostTimeLady
    @LostTimeLady 10 лет назад +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!

  • @NikolajLepka
    @NikolajLepka 10 лет назад +79

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

  • @DanielBeecham
    @DanielBeecham 10 лет назад +8

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

    • @kaitlyn__L
      @kaitlyn__L 10 лет назад +5

      or "the relaxing guy" :3

    • @justahker3988
      @justahker3988 10 лет назад +1

      "The typesetting guy" would be slightly more accurate.

    • @kaitlyn__L
      @kaitlyn__L 10 лет назад

      well, he explained the history of error correction first!

  • @alcesmir
    @alcesmir 10 лет назад +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!

    • @possiblydavid
      @possiblydavid 10 лет назад

      It actually is in the description now.

  • @ButzPunk
    @ButzPunk 10 лет назад +2

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

  • @stedebonnet3151
    @stedebonnet3151 8 лет назад +15

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

  • @duncancarr7822
    @duncancarr7822 10 лет назад

    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

  • @runnerelf
    @runnerelf 10 лет назад +5

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

  • @UnionYes1021
    @UnionYes1021 Год назад

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

  • @dedu15
    @dedu15 10 лет назад

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

  • @frankharr9466
    @frankharr9466 8 лет назад +6

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

  • @frognik79
    @frognik79 10 лет назад +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?

  • @rainmain
    @rainmain 10 лет назад +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 ?

  • @TheSidyoshi
    @TheSidyoshi 10 лет назад +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.

  • @redbaron-jh9kw
    @redbaron-jh9kw 8 лет назад +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 8 лет назад +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?

  • @kujmous
    @kujmous 10 лет назад

    Loved this!!!!

  • @Kabitu1
    @Kabitu1 10 лет назад +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.

  • @matrinGD
    @matrinGD 10 лет назад +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.

  • @madamerosario
    @madamerosario 10 лет назад +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 10 лет назад +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.

  • @GordonPhillips
    @GordonPhillips 5 лет назад

    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
    @AndyBlair 10 лет назад

    This is old school! Very nice :D

  • @Nilguiri
    @Nilguiri 10 лет назад

    ¡Fantástico! Gracias chicos.

  • @Jeff121456
    @Jeff121456 8 лет назад +2

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

  • @salaufer
    @salaufer 10 лет назад +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.

  • @GellyGelbertson
    @GellyGelbertson 10 лет назад

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

  • @razorborne
    @razorborne 10 лет назад +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?

  • @JulianOnions
    @JulianOnions 10 лет назад

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

  • @anothermoth
    @anothermoth 10 лет назад +1

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

  • @SumeaBizarro
    @SumeaBizarro 8 лет назад +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?"

  • @SahilChaturvedi
    @SahilChaturvedi 10 лет назад

    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?

  • @RealDealHolyfield2099
    @RealDealHolyfield2099 10 лет назад

    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.

  • @socearo
    @socearo 10 лет назад

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

  • @u.l.robotics7003
    @u.l.robotics7003 10 лет назад +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?

  • @GeorgeChoy
    @GeorgeChoy 7 лет назад

    thank you, that was awesome

  • @juangreen8194
    @juangreen8194 10 лет назад +8

    as a programmer I find this very interesting

  • @smanzoli
    @smanzoli 5 лет назад

    Loved programming my HP48 in RPN

  • @luvjazz
    @luvjazz 8 лет назад

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

  • @therealEmpyre
    @therealEmpyre 10 лет назад

    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.

  • @GeekIWG
    @GeekIWG 10 лет назад +3

    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.

  • @flydiscovery
    @flydiscovery 10 лет назад

    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?

  • @blmutantx
    @blmutantx 10 лет назад

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

  • @5lammer
    @5lammer 10 лет назад +20

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

    • @5lammer
      @5lammer 10 лет назад +17

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

    • @Niosus
      @Niosus 10 лет назад +18

      Sam Smith (Poor you

    • @ze_rubenator
      @ze_rubenator 10 лет назад +29

      Niosus I hate it when people end in the middle of

    • @aphilra
      @aphilra 10 лет назад +5

      Detecting a little bit of OCD here ;D

    • @daisukekichigoru4900
      @daisukekichigoru4900 10 лет назад +5

      IT'S CDO!!!

  • @pbezunartea
    @pbezunartea 10 лет назад

    nice video!

  • @duncancarr7822
    @duncancarr7822 10 лет назад

    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

  • @DaveScottAggie
    @DaveScottAggie 8 лет назад +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 10 лет назад +1

    I'd like to see some stuff about assembly

  • @nosepickerextreme
    @nosepickerextreme 9 лет назад

    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.

  • @15kalas15
    @15kalas15 10 лет назад

    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?

  • @HadronJack
    @HadronJack 10 лет назад

    Good stuff indeed.

  • @TheSuperkiko98
    @TheSuperkiko98 10 лет назад

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

  • @ybra
    @ybra 10 лет назад +1

    This is very interesting BANG

  • @Deh9o11en8or
    @Deh9o11en8or 10 лет назад +4

    can you please talk about something other than postscript

  • @JunJiePang
    @JunJiePang 10 лет назад +1

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

    • @GegoXaren
      @GegoXaren 10 лет назад +1

      Not a DVD, it is a binder.

  • @xaviripo
    @xaviripo 10 лет назад +2

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

  • @thomasvarney723
    @thomasvarney723 10 лет назад

    Which distro/DE was the professor using?

    • @kaitlyn__L
      @kaitlyn__L 10 лет назад

      elsewhere in the comments says opensuse!

  • @wisteela
    @wisteela 9 лет назад +7

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

  • @datguyoverdere6616
    @datguyoverdere6616 5 лет назад

    this dood is da bess

  • @filippe999
    @filippe999 10 лет назад

    are thse your professor from computer science course?

  • @ghollisjr
    @ghollisjr 10 лет назад

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

  • @sereda008
    @sereda008 10 лет назад +8

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

  • @whackediw
    @whackediw 10 лет назад

    Can you explain how computer gets data from hard drive ?

  • @Portablesounds
    @Portablesounds 10 лет назад +1

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

  • @flapjacksmike
    @flapjacksmike 10 лет назад

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

    • @Turidus
      @Turidus 10 лет назад +1

      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.

  • @robertm4757
    @robertm4757 6 лет назад +1

    Also very entertaining

  • @hunakosdem
    @hunakosdem 10 лет назад

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

  • @whackediw
    @whackediw 10 лет назад

    Can you show how computer gets data from hard drive?

  • @antizubar
    @antizubar 10 лет назад

    Please talk more about algorithms :)

  • @abcvideoyoutuization
    @abcvideoyoutuization 10 лет назад

    Please keep making these video, I wont to program.