7. Evaluation so far

I now have implemented exactly the same functionality in Python as I had available in the TCL/Tk script. It is now time for a short evaluation.

7.1. Speed

The Python script is noticably slower than the TCL/Tk equivalent, epecially at start-up. Something needs to be done about that otherwise Python scripts become unusable.

The speed differnce is mostly in three places:
  • start-up
  • looping over the mysql-cursor
  • adding items to listboxes

The way I found this is by putting time print out in specific functions:
from datetime import datetime
def printnow(string):
    dt = datetime.now()
    print string, dt.second, dt.microseconds

and calling this printnow at specific places in the code. You can ofcourse add dt.minutes but if the execution would require me to add the minutes, I would abandon any further exploration of Python.

The result for the looping over the cursor ('cursor.executed' to 'copied to the list') are 1.3 seconds, as can be seen below:
get_selection 45 470185
cursor.executed 46 249354
copied to the list 47 554510
showlist start 47 554571
list cleared 47 633019
list filled 48 351590

The complete update of the listbox from the database is 2.8 seconds, which is clearly much more than the almost instantanous response from TCL/Tk.

7.2. Code size

Python's code size in lines is significantly larger than TCL/Tk. Python is a language that likes to do everything vertically. With a maximum linesize of 80 characters, the codesize in lines quickly becomes very large. The python version is 549 lines, and the TCL/Tk is 337. In characters, Python is more than 75% larger.

7.3. Readability

Code from Python is marginally better readable. My screen is (vertically) around 80 lines, which makes it impossible to get a good overview of sections in the Python code in one screen. The punch-card restriction of 80 columns, compared with the 180 columns of the terminal screen, makes it feel like Python has made some odd choices.

7.4. Variable typing

One thing that is bewildering is the strong typing of Python in combination with its dynamic typing.

In Perl, you can:
print $b;

to get "1+1=2".

In Python, this results in:
>>> a=2
>>> b='1+1=' + a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  TypeError: cannot concatenate 'str' and 'int' objects

Note that you can assign a='2' even after it once was an integer. That is called dynamic typing.

The combination of dynamic typing and strong typing gives additional constructions like:

which require quite a bit of Python specific reasoning to justify.

7.5. Libraries

Python has a lot of libraries that do different things, and many that do the same thing. There is no way to tell if these libraries will be continued, if they are part of standards or anything like that.

Further more, all sorts of installation methods are used, from slapt-get to easyinstall and pip install and let's not forget compiling from source. The libraries are also all over the place; a standardization in location seems difficult. Add to this the version 2 and version 3 problems and the frameworks, and you'll get XKCD's installation of Python.