Andy Callaghan: Pythonian

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()”

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. 
This entry was posted in Rant, Uni, Work. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>