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! 


No comments:

Post a Comment