Showing posts with label PDP-11. Show all posts
Showing posts with label PDP-11. Show all posts

20201115

Love hate Python

There was Visual Basic 6 (VB6)... and then there was Python.  Both are interpreted languages (i.e. they run from a high-level script rather than being compiled into machine code). Both claim to be easy to program with and both have a huge following. Python is current whereas VB6 is no longer supported.  Python is free whereas Microsoft have made VB6 neither free nor available but say that it is superseded by VB.NET.  But these are very different languages. Having sharpened my teeth on plain BASIC (e.g. BASIC PLUS in college days, QuickBASIC running under MSDOS) I progressed to VB6 which I used extensively for creating test software to exercise electronics I have designed in the course of my work.

In case I ever have the privilege of helping homeschoolers here with teaching computer science, I figured I ought to learn a current language. I did a bit in C# a few years back for a work project and, whilst C# is a very powerful language (meaning you can do certain complex things with minimal coding), I found its syntactical gamut too much for my poor brain. So, what more suitable to up-and-coming programmers than Python, or so I have been told?

Many years ago I authored some QuickBASIC code that would display prime numbers in a square spiral.  The essential part took a mere 20 lines of script, and here's the output, limited to the VGA 640x480 screen resolution of the day with each integer represented by a single pixel. You can click on each image to zoom in.



The point of the program, apart from being an exercise in graphical output and being cool, is to highlight the mainly diagonal line patterns that prime numbers arranged in this way make. Anyway, this became my first Python challenge.

Here's the output of my Python code - a bit prettier because now each integer is represented by a 4 x 4 pixel square. Value 1 is plotted as a blue square, otherwise primes are red and non-primes grey. The essential part was almost 100 lines of code and took a long time to code. OK, so I am a novice but even so...  I tested it with three different algorithms for finding the primes - the fastest involved saving the primes in a Python list.


And here's the same in VB6.  It was so much easier to do the graphics part in VB6.  Python graphics is anything but intuitive and seems to employ the longest path to achieve the least credible results, whereas in VB6 you simply drag and drop graphic widgets and then click on them to open their respective code space. That they are event driven is taken for granted unlike Python.



Oh, and although no-one on ever claimed VB6 was fast, without pausing to do animated screen redraws I found my VB6 code ran about twice as fast as with Python.  I tried different prime algorithms but found the VB6 code ran fastest by dividing each integer numerator by all the denominators from 2 up to the square root of the numerator, which for large integers involves many more test divisions than did my Python code. That VB6 was still significantly faster says something in its favour.

And then, although Python is an interpreted language like VB6 or QuickBASIC, it has no native integrated development environment (IDE) so testing and debugging entails constant swapping between your chosen text editor (I used Notepad++) and the command line.  Although there are 3rd party IDE's and I am currently investigating Microsoft "Visual Studio Code" which, surprisingly, is free.

So do I love Python? Well, not yet, certainly! 


20120718

Computing at Oxford

I met the computer for the first time at Oxford. How strange that sounds today when it is not unusual for everyone here in the lounge to have a laptop of equivalent on their lap.  But in those days, before the IBM PC, it was not so.

IBM 1130 (similar to, but not the one I used)

My friend and I attended an extra-curriculum computer course.  Not having the internet to check this out beforehand, I had not a clue what it was about and it took a while for the penny to drop that you could actually tell the computer to do stuff, line by line.  And so we learnt Fortran IV, and exercised our new found knowledge on the Nuclear Physics Department IBM 1130 with its 32K-word core memory, card reader and, oh joy, a pen plotter.

The IBM 1130 was single-user and single-task. You "typed" your program on a card punch machine in a cubicle in some remote and very noisy room.  Each card described a statement (a line of code): the card in the picture is one of my own and describes an IF statement.


A typical program would thus end up as a stack of cards several inches thick. You would take this to the computer room and join the queue. When eventually your turn came you would place the cards in the card reader which would read them surprisingly fast (woe betide any cards that were dog-eared!) and your program would either execute as intended or not.  As with most programs, generally it did not execute correctly for the first many tries.  There was no way to tinker with it there and then - there was a queue of other users behind and besides there was no card punch in the computer room.  So, back to the cubicle.

The computer bug really got to me at first - I remember my parents coming to collect me at the end of term and feeling like a zombie - we stopped outside Newbury for a picnic on the way home and I can remember the juxtaposition of the "homely" taste of the sandwiches and the surreal, almost drunk feeling of utter fatigue. When we got back home I went to my room and slept for a very long time.

Here are some of the programs I can remember writing:

(1) I was very pleased with myself for simplifying the maths of solving multiple simultaneous linear equations by the reduction to echelon form method.

(2) As mentioned in a previous post I made a program to print out ground-hogs subjected to various graphical transformations (skew, enlargement, reflection, rotation, etc.) .  This partially in eternal devotion to the ground-hog artist previously mentioned, and partly because a pen plotter must be brought into submission.

(3) The pièce de résistance was a joint effect. It absorbed colossal amounts of effort. My friend wrote the main program and I wrote the subroutine. The whole thing developed a musical theme into a fugue and plotted it out in high definition in full harmony on two staves. The subroutine (I called it "note" I think) dealt with the graphical aspect.  The call specified the pitch and length of the note(s) and the subroutine would work out whether it first needed to plot staves, ledger lines, bar lines, time and key signatures and the like and then would draw the note appropriately. Regrettably I have nothing to show for my work: I gave the final plot to my friend and we felt we could not repeat the exercise for fear of stretch to ultimate distraction the patience of the other programmers who wanted to use the computer for what they thought were "serious" purposes.

++++

The second computer in my life was the PDP-8 at the Clarendon Laboratory.


This picture is the closest I could find to what the setup was.  There was a single teletype for creating punched paper tape and interacting with the computer.  The computer itself had a high speed paper tape reader that would read literally piles of tape in seconds.

The PDP-8 was classed the "first minicomputer".  It was pretty close in power and speed to a Microchip PIC16 microcontroller which is a "chip" costing much less than a euro today - a rather large example is shown below.  In case you didn't catch it, this is somewhat of a condemnation of the PDP-8.  Like the PIC it had a 12-bit instruction code, this being rather unusual in a computer.  And probably a similar amount of memory.


Again this computer was single-user, single-task.  It had no disk drive and no internal operating system, so each task had to be loaded from scratch from paper tape starting with the operating system.  Programs were written in FOCAL which was not dissimilar to a very basic sort of BASIC.  The machine was used mainly to carry out linear regression analysis on experimental results.  As computers go (back then) it had very little character - a lot less than the IBM 1130 because it had no plotter.  But the concept of linear regression fascinated me and I taught myself to derive the equations from first principles and then extend to polynominal regression analysis complete with adjustable weighting on each data set.  Any student of elementary calculus would appreciate this task - it is very satisfying.

For you youngsters reading this, a "teletype" was a wondrous machine.  It was, I suppose, a derivative of the telex machine. It is entirely mechanical, the only electrical parts being a motor to drive the works, and a solenoid to convert the electrical pulses sent from the remote computer to actions and some sort of switch for the inverse operation.  So doing, you could type at up to 10 characters per second and, low and behold, the whirring gears would convert this to a pulse stream at 110 baud and send it to the computer.  Conversely the computer could drive the type-writer action, again at a maximum speed of 10 characters per second.  No lower case letters mind you.

++++

The third computer in my life was the PDP-11 in the inner sanctuary of the Nuclear Physics Department.  Its discovery was like finding something out of Star Trek - a vast room filled with racks of equipment and magnetic tape readers constantly spooling tape to, I suppose, seek particular data.  Whilst this behemoth was doubtless built for advanced physics experiments beyond my undergraduate ken, I found out that ordinary mortals could use terminals connected to it.  The operating system being multi-user, about 20 teletypes were available in a room away from the machine itself.  Later these were provided with monitors so that output was not limited to 10 characters per second.  The monitors were, of course, monochrome and strictly text only.  But, oh, so much superior to the teletype output (unless you wanted a hard copy).

Mortals like me wrote in BASIC PLUS.  This was a very powerful language which included, for example, matrix instructions such that the simple statement:
MAT Q = INV(Z)
calculated the inverse of a 2D matrix of arbitrary size, and anyone knows that this is an essential step in the "reducing to echelon form" method that I had previously laboriously worked out long-hand.

The PDP-11 had hard disk storage and each (ordinary) user was allocated room to store his or her programs, luxury indeed compared with punched cards!  The trivial amount of storage allocated would shock modern users. One of the great sins of our time is the waste of data storage, and one of the greatest sinners must be the Microsoft Corporation - or is it the digital camera?

++++

The forth and last computer of my life until after I emerged from hibernation was the mini-computer at the BBC Research Department.  I regret I cannot even remember the brand or operating system - was it CP/M?.  It was located in an air conditioned room ruled over by a nerd.  It had hard large disks and an 8" floppy disk drive. Being multi-user each department had one or maybe two terminals (teletype style).  By way of example of the technology back two software packages it boasted were a BASIC interpretor which you were encouraged not to use because, whilst loaded, it used up a large chunk of available RAM, and a word processor program.  To use the word processor you would type your report at the terminal using embedded formatting codes (e.g. for italics, indent).  You would then run the word processor software which would apply the formatting to this data and write an output print file.  Finally you would beg to be allowed to use the one and only high quality printer which was basically an electric typewriter, and then go and collect the print-out from the computer room (in another building).  Inevitable mistakes would mean repeating the whole process several times before the end result was sufficiently perfect (what a waste of paper!).

I left the Research Department after about 5 years and went into electronics-hibernation for another 5 years.  When I finally emerged (relatively unscathed, but that is another story), the world had changed.  The PC had been born and people had began to speak of mice and GUI's...