Learning Python

I've been learning something new this week (which happens on a regular basic), but this time it was very official, I actually went to a training.

It was decided, that I had to learn Python, which is a [stag]programming language[/stag], and yet another of the scripting ones - we already have Perl, PHP, Ruby, and so forth, which meant that I actually was in some sort of pathetic way was looking forward to see what all this was about.

There is one thing which is annoying about Python, and it's even worse that they have decided not to do something about it. They have not implemented a 'switch' statement, they have some obscure reason why;
It is too early to decide. I'd like to see at least one completed proposal for pre-computed values before deciding. In the mean time, Python is fine without a switch statement, and perhaps those who claim it would be a mistake to add one are right.

The whole thing is discussed here.

A switch statement is used to in a very simple way do a selection:

switch( variable )
   case 'a' : do something if variable is a
   case 'b' : do something if variable is b
   otherwise/else : do something if variable is neither a nor b
end switch


Instead they they have decided that 'if' is a lot better. The same as above just with 'if':


if variable == 'a' then
   do something if variable is a
else if variable == 'b' then
   do something if variable is b
else
   do something if variable is neither a nor b


Well it does not take long to see that using 'if' does work, but it will look like a mess, which is avoidable by using 'switch'. Well until further notice there is no other option than to use 'if' - sadly enough.

But there are good things also, it have a tight integration to the OS, which means that the whole Std. C Library is there (more or less), and also lots of other things is available. On Linux for example there is integration to both KDE (QT) and Gnome (Gtk2), on OSX there is Coca, and Carbon, and an interface or ObjectiveC (PyObjC). The nice thing is that on OSX it's available from Xcode (integrated development environment). I don't know about Microsoft Windows, as I don't have much interesting in dealing with Windows development these days (as I do this for fun).

Everything is an object, but due to the way namespace is dealt with, one end up doing strange things. For example, to use sqrt (square root), one would do;

import math
x = math.sqrt(9)

and not like in C/C++

#include <math.h>
....
x = sqrt(9)
...


Of cause there are ways to get around the namespace thing, but it's slightly annoying.

But in general, it a usefull language, lots of things are using it; like Xen (hummm, yes). It's easy to do prototyping in, and one could actually use it for application development, there are a enough libraries to make it possible. The designer tools on Linux can generate Python code, so nothing is stopping you from writing stuff in Python.

The best of luck....


Comments

A fantastic read....very literate and informative. Many thanks....what theme is this you are using and also, where is your RSS button ?
casper said…
Thanks, either at the bottom of the page, or somewhere around where you type the URL...

Popular posts from this blog

Apple AirPort Express and Digital Jitter..

EIZO Colornavigator - Data Access Error

Using Borg backup across SSH with sshkeys