Wednesday, January 16, 2008

Motivation

So where do we begin? Well with how this blog came about...

I have been thinking about writing some of this stuff down for some time, but a few recent Python related posts have motivated me to getting out and having my say on the matter. A few weeks back was this XKCD cartoon
which probably sums up how us enthusiasts feel about the language.
Welcome to our world, Randall.

But just yesterday I noticed this entry that said Knuth had suggested using indentation for program structure many years ago. Since one of the perennial bugbears that arises in Python advocacy is the use of significant whitespace, having DEK's seal of approval puts the final nail in the coffin of the naysayers. The Knuth books have been a source of information and inspiration to me for many years and I have pored over every line and worked through most of the exercises in search of a mistake (motivated by the desire to score one of the checks). I did find one mistake a few years ago but I had been beaten to the punch by a few months as it turned out. I did manage to get a $0.32 'valuable suggestion' check last year by solving one of the problems in a new and different way, and Python was instrumental here. More on that sometime in the future, it is a good story and demonstration of the power of the language.

The bottom line is: suck it and see. The use of whitespace indentation
for structure is elegant. You will get used to it. ESR did along with many others.

I won't go over the interminable arguments that are raised against whitespace structure. For me, the indentation makes code readable and unambiguous. It just works (for me anyway). End of story. And as I said in the previous entry, for an old FORTRAN user, it never was an issue.


The indentation works as does the language as a whole. (Again, for meanyway). This may be related to the sort of engineering/scientificproblems I tackle and the environment in which I work. The librariessupplied with Python cover just about everything I need and it is easy tofill in the gaps. Speed is never an issue: for number crunching onhomogeneous arrays we have Numpy, and if there is anything which can't bemodelled there, swig is your friend. Or ctypes. The possibilities are endless.

Anyway, I digress. Seeing the whitespace issue raised yet again just made me feel it would probably be worth putting in my $.02 worth. So here we are.

So enough motivation and advocacy for the time being. I'll try and address some interesting problems that I have solved efficiently using Python. The sort of problems of interest to an engineer/scientist working with real world issues. I have yet to find any real reason to become au-fait with closures, functional programming and a lot of the other topics that get discussed in some of these forums (forii?) Python may or may not handle these but it is certainly good for useful (to me) stuff.

Tuesday, January 15, 2008

Python Homecoming...

After about thirty years of wandering around the planet, living and working on four continents I recently settled back to a small beachfront town in Australia, the country where I was born.

And after over thirty years of wandering among computer languages I have finally settled on one that I feel will last me for the rest of my career.

The language is Python, and using it makes me feel like I have come home: hence the title of this blog.

I started with FORTRAN on punched cards many years ago. And with Python, I can still write FORTRAN if I need to. Both literally and figuratively as I will get around to discussing.

Most of my software development is numerical algorithmic in nature: my code tends to consist of long series of primarily numerical expressions interspersed with logic. So Python is the closest language I have found to FORTRAN when it comes to writing numerical expressions. And one regular but ill-judged complaint about Python - its use of indentation as a structuring mechanism - is no obstacle to anyone who grew up with FORTRAN!

FORTRAN:
y = x**5 + sin(z)

python:
y = x**5 + sin(z)

compared to

tcl:
set y [expr {pow($x,5) + sin($z)}]

c++:
y = pow(x,5)+sin(z);


So my software environment started with FORTRAN, moved to C in the early 80's, then to C++. There were various side excursions: FORTH, Pascal and Java came and went. Along the way I became aware of scripting languages, which were an easy way of doing a lot of things that didn't need the full power of a compiled language and let you make GUI's for applications with comparative ease. I started with Tcl/Tk, had an occasional foray with perl, but when I came to do a fairly major project, I picked on Python for the job because it seemed like a good language with class and GUI support, and particularly well documented.

I learned the language, finished the application and never looked back. Python has let me solve a lot of interesting problems, write a number of useful applications, got me a Knuth check and generally made life easy. I figure I am 'retired' now, I don't need to learn any new languages because there is more than enough new useful stuff still going on in the Python world to keep me interested.

Anyway, this blog will talk about the history of how I ended up coming home to Python, undertake a bit of advocacy, and generally be a post for interesting and useful (to me) stuff that I run across in my daily work. The emphasis will be on numerical/analytical techniques rather than hardcore language issues.


And I enjoy Monty Python as well! Thanks Guido for giving us this wonderful language.