Vivek Nallur (nvivek) wrote,
Vivek Nallur
nvivek

first python project

By sheer chance, I've started using Python for my experiments. I'm coding up a double-auction market with buyers, sellers, applications that ride on top of buyers and strategies. It's basically a discrete event simulation package and by far the definitive implementation is JCAT (http://jcat.sourceforge.net/). In a PhD, since you get absolutely no credit for writing any code at all, my advisor was quite keen that I spend the least amount of time setting up the experiment. So I spent all of the christmas hols, hacking through JCAT and by the first week of Jan, gave up. There were just too many changes to the protocol and the entities, for it to be a clean end-result.

I decided to chuck everything and start afresh with SimPy. In two weeks, I've got a working (somewhat) marketplace. This is more than where I reached in three weeks with Java. I had forgotten how much of a boost a scripting language gives, to programmer productivity. Keeping in mind, that I'm fairly comfortable with Java and this was my first *ever* python program. I haven't written a hello world before this.

I simply read the SimPy tutorial and started coding. Of course, it helped that I'm fairly comfortable with Ruby, so a lot of the concepts translate smoothly. I still get stuck when 'the Ruby way' doesn't work in Python, but then this is more a problem with my understanding of Python than Python itself. But there are some syntactic peeves that I think, that Python could've avoided. The colon as a block marker, for instance. I didn't particularly feel odd about the indentation rule (I really don't understand why lots of people crib about this. One would do it in other languages, anyway. Set autoindent on in Vim, and you're off!), but I keep getting caught out by the need to insert a colon at the header of every block de-lineator. Also, the three-scope rule could've really accommodated instance variables inside methods, instead of making the programmer type self.X every time. The interpreter's error messages could be a little more verbose than the bland 'syntax error at line'. I guess, I'm expecting something more on the lines of the perl/ruby interpreter. For instance, I was trying out a conditional inside a list comprehension and all the interpreter told me was that I had a syntax error. Now, I'm sure that it's perfectly obvious to a seasoned pythonista, but it doesn't hurt to give the novice a hint, now and then. More functional constructs like inject would be handy, too.

All that being said, I'm extremely satisfied with the state of the code and Python. Given that I'll have to build on this experiment, all of my coding during the Phd will probably be in Python. Even at this novice stage, that feels more satisfying than contemplating writing it in Java.

Bet chirag will have a little smug smile on his face, if he reads this. It's high time you did a few ruby libraries too, mate!
Subscribe
  • Post a new comment

    Error

    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 2 comments