views:

587

answers:

7

I'm currently reading a great book called 'Programming Collective Intelligence' by Toby Segaran (which i highly recommend)

The code examples are all written in Python, and as I have already learnt one new language this year (graduating from VB.net to C#) i'm not keen to jump on another learning curve.

This leaves my with the issue of translating the python examples into C#.

Question is: How critical is it that the code stay in python? Are there thing in python that I can't do in a normal managed statically typed language?

+17  A: 

One challenge you'll find is that not only are the algorithms implemented in Python, but the book makes extensive use of Python libraries like BeautifulSoup, Numpy, PIL, and others (see appendix A).

I doubt there are any specifics of the algorithms that you couldn't port to another language, but you'll have trouble working through the exercises. Also, to translate the code, you'll have to learn Python at least a little bit, no?

I suggest you just dive in and learn Python. You can use IronPython if you have any concern about interoperability with your C# projects.

Joe Germuska
+1: to translate the code, you'll have to learn Python
S.Lott
Exactly. Knowing Python will be necessary to translate it. Part of the reason people use Python is because of the many quality libraries available. To have to translate the code of interest *and* the libraries would be a burden much larger than just learning Python :-)
Doug
Is IronPython something you recommend?
Harry
I can't exactly recommend IronPython because I don't do any .NET development, but at PyCon I got the sense that there is a strong interest in maintaining parity among the different implementations of Python... so if you need .NET integration, use IronPython. If your Python will run standalone, it will probably be a little more straightforward to use C-Python (that is, the most common Python) until .NET integration matters.
Joe Germuska
+1  A: 

Obligatory XKCD: http://xkcd.com/353/

I know you explicitly say you don't want to learn Python (this year), but translating the Python examples to C# will definitely be a much steeper curve. Just dive in!

akent
C:\Python30>python -m antigravity
THC4k
+2  A: 

You can do the same things in all Turing-complete languages. Here is an example for rendering a Mandelbrot fractal in SQL. The example shows: Even if you can use any language, the effort will be different.

So my guess is that the code will become much longer since Python is so flexible and open.

Aaron Digulla
+1  A: 

The book is about algorithms, not the details of programming, and the language of choice is just to make the examples concrete. As the author says, "The code examples in this book are written in Python... but I provide explanations of all the algorithms so that programmers of other languages can follow." (p. xv)

Python is a great language and easy to learn, but I suspect the difficulties in applying ideas from the book will not be in the translating of the code to another language or set of libraries, but in understanding the ideas and modifying the code to suite your needs. I think there are two main reasons to stay with a language you're familiar with: 1) when your code doesn't work, if you're writing in an unfamiliar language, you won't know where to start looking for errors, e.g. if you're like most people you'll even start wondering if it's due to a bug in Python, which it won't be, but you'll wonder and it will distract. 2) There are just natural limits to how much you can remember in a certain length of time; and learning a language at the same time will give you twice as much to remember.

It depends though how well you know C#, and what you lose by leaving it.

tom10
A: 

Python seems to be to AI programming what LISP was for for many decades. Russel/Norvig's famous book AI: A Modern Approach also provides lots of examples in Python.

wr
+2  A: 

I suggest translating them to C#. I have been porting chapter 2 "Recommendations" to VB.Net. Along the way I'm learning Python as a side-effect. Toby does some amazing things with Python lists.

Dealing with the the extra Python libraries is another story. Ndelicious is a close match to pyDelicious, but it is missing a few key features (popular posts!).

Jamison
+1  A: 

Just learn it already!