tags:

views:

310

answers:

7

I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange. Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?

+9  A: 

Yes, I do think that Python would be a good replacement. I understand that the Twisted Python framework is quite popular.

Lyndsey Ferguson
Twisted is a great library for this sort of thing
johnc
Twisted may not be necessary for this, however. The socket or asyncore modules may be sufficient.
S.Lott
Twisted is a lot of headache to replace something that already works. If socket is sufficient, use it!
Gregg Lind
I was thinking of using Twisted to run a cross-platform server, what should I watch out for? Thanks.
Lyndsey Ferguson
+1  A: 

Assuming that you have control over the environment which this application will run, and that the performance of interpreted language (python) compared to a compiled one (C) can be ignored, I believe Python is a great choice for this.

Alan
Python is not interpreted, it is byte-compiled, and three JIT compilers exist (psyco, PyPy's old JIT, PyPy's new JIT), not counting the pre-existing JIT for Java and .NET (for Jython and IronPython respectively). And since it'll be IO-bound, the assumption is likely correct.
Devin Jeanpierre
I believe my original statement is correct. http://en.wikipedia.org/wiki/Interpreter_%28computing%29
Alan
Fair enough. I was thinking of category 1.
Devin Jeanpierre
+4  A: 

I'd say that if:

  • Your C code contains no platform specific requirements
  • You are sure speed is not going to be an issue going from C to python
  • You have a desire to not compile anymore
  • You would like to try utilise exception handling
  • You want to dabble in OO
  • You might choose to run on many platforms without porting
  • You are curious about dynamic typing
  • You want memory handled for you
  • You know or want to learn python

Then sure, why not.

There doesn't seem to be any technical reason you shouldn't use python here, so it's a preference in this case.

BenB
+1  A: 

If I was faced with a similar situation I'd ask myself a couple of questions:

  • Is there anything more important I could be working on?
  • Does Python bring anything to the table that is currently handled poorly by the current application?
  • Will this allow me to add functionality that was previously too difficult to implement?
  • Is this going to disrupt service in any way?

If I can't answer those satisfactorily, then I'd put off the rewrite.

toast
+2  A: 

Remember as well, you can leave parts of your program in C, turn them into Python modules and build python code around them - you don't need to re-write everything up-front.

too much php
+1  A: 

Yes, I think Python is a good choice, if all your platforms support it. Since this is a network program, I'm assuming the network is your runtime bottleneck? That's likely to still be the case in Python. If you really do need to speed it up, you can include your long-since-debugged, speedy C as Python modules.

Kevin Conner
A: 

If this is an embedded program, then it might be a problem to port it since Python programs typically rely on the Python runtime and library, and those are fairly large. Especially when compared to a C program doing a well-defined task. Of course, it's likely you've already considered that aspect, but I wanted to mention it in the context of the question anyway, since I feel it's an important aspect when doing this type of comparison.

unwind