Dev @ Work

A day in the life of a developer

Python, without using Python

August 26th, 2008 by Trilobyte

Today I faced a problem at work: I had to come up with a flexible, extendable architecture for a XML-RPC client service application. Both the client and server code had to be integrated into existing applications which makes the impact of introducing new message handlers painful if not designed properly.

While thinking about those requirements I quickly thought of a concept I saw in Python: Try to call find a callable method, otherwise do the default action. In Python you can use ‘getattr(…)’ to get a possible method of a class and with ‘callable(…)’ you can check if the method is actually a method.

You get something like this on your dispatcher object:

def Dispatch(self, methodName, arguments=None)
   method = getattr(self, methodName, None)
   if callable( method ): method( arguments )

I implemented this extensible architecture in exactly the same way. It was fairly easy to do, painless and it is extensible.

Learning multiple programming languages/concepts pay off!

Learning Python part 2

August 19th, 2008 by Trilobyte

I just finished the book ‘Beginning Python, from Novice to Professional’ written by ‘Magnus Lie Hetland’ and it has been a great experience for me. I have played with Python a little and I have discovered a few features I wish C# supported.

The most powerful feature of Python, in my opinion, is the ‘slice’ operation: It allows you to efficiently select a portion of a collection by providing 2 indexes.

For example:

>>> word = 'Hello, World'
>>> word
'Hello, World'
>>> word[6:]
'World'
>>> word[1:2]
'e'
>>> word[-5:]
'World'

If I ever had to write an interpreter, I would write it in Python, because of the ‘slice’ operation it is a natural thing to do.

Another thing that I like about Python is that it is a dynamic language. You can do some really cool stuff like: ‘runtime dynamic method invocation’. It is supported in C#, however, it is painful and unnatural.

One thing I don’t like is that you are forced to use ‘self’ as an argument on every instance method. I understand the concept but in my opinion it to much of a hassle.

For me personally, learning Python gave me more insight into the problems I encounter daily in C#, because I learned to solve the same problems in different ways, which might be more efficient.

My conclusion is: Every developer should think about learning multiple programming languages, preferably not in the same family (like C based languages), so he/she is able to select the right tool for the job and keep an open mind. That is it for now, I hope I will have some time to write something cool in Python.

Learning Python

August 1st, 2008 by Trilobyte

Yesterday I started reading the book ‘Beginning Python, from Novice to Professional’ by ‘Magnus Lie Hetland’ and so far it is really interesting. I choose to learn Python because I wanted to learn a new, non C based, programming language.

I am really looking forward to write some programs in this powerful language. I will keep you posted!

Posted in Books, Python | No Comments »