Sunday, January 20, 2008

Python and SAGE

Honestly, I've always been a rather staunch C/C++ programmer, ever since they gave up supporting QBasic and the rise of GNU/Linux as the "new" hacker-friendly operating system. But after two days of programming with python and SAGE, I must say that python (and its math-oriented superset, SAGE) now rank among my favourite languages.

Python programming is in some ways like the best of C/C++ and Standard ML; python has a decent object oriented programming interface, a decent imperative programming interface, and a decent functional programming interface. The ability to use these three interfaces interchangeably in a single source file is something that I appreciate a lot. For example, some things are more intuitively done with a functional programming interface than through an imperative one, not that C/C++ cannot do it, but the way it is done in python is rather straightforward (just pass the name of the function) as opposed to that done by C/C++ (you pass the name of the function, except that when you write code that uses the passed function, you need to deal with a rather peculiar syntax for function pointers). Also, some things (like mapping over a list of items) are more intuitively done with functional-styled programming than imperative.

Some peculiarities of python need some getting used to. Functions and lists are literally first class citizens in the language, which means that most of the operations that are available off the compiler/interpreter often take lists/functions as parameters. Not that this is bad/inefficient, but it sure takes a little getting used to as opposed to the usual for-loop in C/C++ with counters and stuff—python supports a for-loop whose style is more for iterating through items in a list. Strangely, that doesn't impair me a single bit, since I don't usually use complicated for-loops to start with.

Overall, it is a rather interesting experience in writing code in python. The only reason why it took me so long before I actually started on it was the fact that in its earlier life, python wasn't stable enough for use—the language seemed to be rather ad hoc and have no real structure, and there wasn't a standardised distribution nor a standardised language feature list. Now that python is in a more stable state, it seems rather apt that I play around with it and increase my programming language repertoire once more.

——

In other news, I really want a flute with a B-foot. Not that the C-flute is bad, but that I'm really interested in taking my flute playing skills to a new level. Currently, I'm rather competent with notes that are within the staff, but notes on the upper ledger lines are still killing me on a regular basis. Considering the fact that I now own some practice books, it'll probably be much easier in getting the hang of those pesky upper ledger line notes. That all said and done, it is back to the grindstone for me in finishing more of my homework that is going to be due rather soon.

Till next time.

No comments: