Andy Callaghan: Pythonian

Posted on December 8, 2007 by Andy Callaghan.
Categories: Rant, Uni, Work.

I have recently found myself deviating away from C and C++ towards a newer, cleaner, smarter and much less annoying programming language - Python.


I was knocked back from it’s sheer simplicity in code and the vast selection of built-in libraries for easy programming. For example this one line of python code broadcasts a web-server on port 8000:
python -c “import SimpleHTTPServer;SimpleHTTPServer.test()”
From Gary Robinson’s Rants

Ridiculous! And how about this… completely tokenise a string, one line:
“Hello my name is Andy”.split(’ ‘)
This one may not seem too amazing; php has the explode() function which basically does the same, but this very piece of code took me well over 50 lines of C code to do exactly the same thing. 

Also Python natively supports Regular Expressions, whereas it would have to be a dodgy undocumented class add-on for C++.

This is exactly why I have chosen to do my next piece of Compilers coursework in Python. We are to construct a compiler that has an input of a self-defined language, use Lex (or equivalent) to produce perform lexicographical analysis and tokenization, Yacc (or equivalent) to produce the parser for the language, and my brain (or equivalent, i.e. Google, Wikipedia et al.) to produce efficient assembly language for the input source.

Just starting this coursework in C++, would involve extensive research to discover how one would accomplish the first two stages, let alone the last – and evidently most important one.

However in Python, I have imported the built-in Lex and Yacc tools, written 62 lines of code and the code already tokenizes and parses my custom language. All that’s left is the funny error messages (see below) and assembly code production.

Funny compiler error messages in Python
I’m never turning back. 

There go my printer credits…

Posted on December 2, 2007 by Andy Callaghan.
Categories: Rant, Uni.

My XML coursework is finally done. As I couldn’t get any work done at home, I went into Uni from 5 on Saturday…

… at 2am, I finally left with the coursework done. I walked back home feeling zombified with companion from exceedingly drunk Union-ites. This is a screeny of my report properties:

Document properties of XML report

Yes… that’s 6 hours 2 minutes and 58 seconds of editing! Ouch.

During printing the 23 full colour pages of the report, my printer credits plummeted…

The fall of computer credits...