07 August 2010

Silverlight 4 with C# and Python (it's three!)

I recently felt like making a new Silverlight 4 app, but not just any app. I wanted it to have the following features:

  1. use an existing Python library
  2. be written in C#.
There is a way better way of using Python code - it is to write the app in Iron Python from the start. Picking C# to achieve that sounds like a bad decision.

However, I wanted to do something new and challenging, so I went for C#. Doing it on my own was hard, way harder than just following an "embedding Python in C#" tutorial. Finally, I found that working example and got something starting from there.

What I got is a three on a golden background:

Okay, maybe that's not the right angle to start with. What I did was used the numbthy Python library and used it's gcd function to compute the greatest common divisor of 15 and 3, and it's three!

Getting there was hard. Finding the right libraries to embed Python, importing them the right way were tough tasks for an inexperienced user - some error messages would be very cryptic. Then, the app would hang on the splash screen if something was wrong in the Python code, the debugger wouldn't show where the problem was, and the "problems" in the Python code were:
  1. the print statement
  2. a class inheriting from object.
Not obvious, and definitely not the kind of problems PyDev would warn you about. So I am afraid that importing bigger chunks of code could be hard - that is to be explored further.

No comments:

Post a Comment