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?
-
Yes, I do think that Python would be a good replacement. I understand that the Twisted Python framework is quite popular.
johnc : Twisted is a great library for this sort of thingS.Lott : Twisted may not be necessary for this, however. The socket or asyncore modules may be sufficient.Gregg Lind : Twisted is a lot of headache to replace something that already works. If socket is sufficient, use it!Lyndsey Ferguson : I was thinking of using Twisted to run a cross-platform server, what should I watch out for? Thanks. -
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.
Devin Jeanpierre : 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.Alan : I believe my original statement is correct. http://en.wikipedia.org/wiki/Interpreter_%28computing%29Devin Jeanpierre : Fair enough. I was thinking of category 1. -
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.
-
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.
-
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.
-
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.
-
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.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.