9

I created a module in Python which provides about a dozen functionalities. While it will be mostly used from within Python, there is a good fraction of legacy users which will be calling it from Perl.

What is the best way to make a plug in to this module? My thoughts are:

  1. Provide the functionalities as command line utilities and make system calls
  2. Create some sort of server and handle RPC calls (say, via JSON RPC)

Any advise?

3 Answers 3

19

One other choice is to inline Python directly in your Perl script, using Inline::Python.

This may be simpler than other solutions, and only requires one additional module.

Sign up to request clarification or add additional context in comments.

2 Comments

Inline::Python works quite well, there can be some strangeness when passing certain kinds of variables though.
Thank you. I liked all the answers, but this seems very portable.
9

In the short run the easiest solution is to use Inline::Python. Closely followed by calling a command-line script.

In the long run, using a server to provide RPC functionality or simply calling a command-line script will give you the most future proof solution.

Why?

Becuase that way you aren't tied to Perl or Python as the language used to build the systems that consume the services provided by your library. Either method creates a clear, language independent interface that you can use with whatever development environment you adopt.

Depending on your needs any of the presented options may be the "best choice". Depending on how your needs evolve over time, a different choice may be revealed as "best".

My approach to this would be to ask a couple of questions:

How often do you change development tools. You've switched to Python from Perl. Did you start with Tcl and go to Perl? Are you going to switch to the exciting new language X in 1, 5 or 10 years? If you change tools 'often' (whatever that means) emphasize cross tool compatibility.

How fast is fast enough? Is the start up time for command line solutions ok? Does Inline::Python slow things down too much (you are still initializing a Python interpreter, it's just embedded in your Perl interpreter)?

Based on the answers to these questions, I would do the simplest thing that is likely to work.

My guess is that means in order:

  1. Inline::Python
  2. Command line scripts
  3. Build an RPC server

Comments

3

Provide the functionalities as command line utilities and make system calls

Works really nicely. This is the way programs like Python (and Perl) are meant to use used.

10 Comments

Hard to beat simple and well tested, isn't it?
Except of course if they need to run in an environment where startup cost of a Python interpreter (times # of expected executions) is way too high. Like an app or a web server, as an example. The way Perl is meant to be used in a situation-appropriate way.
@DVK: Python can be used in a variety of ways, also, each appropriate to different situations. Do you know what situation applies to this question?
@S.Lott - I don't know, but my point was that you don't know as well, yet you recommend one solution WITHOUT explicitly explaining which circumstances it's suited to. And, to be honest, the fact that the OP mentioned a server with RPC calls inclines one to think that there probably was some reason why they did not consider command line system() calls to be the obviuous solution
@DVK: My point was that you seem overly critical about a valid solution without any real basis in fact. You could -- for example -- ask for clarification from the person posting the question rather than make assumptions. I find that many people are ignorant of the standard Unix design pattern of lots of cooperating processes. If this is a pipeline between Perl and Python (where both processes run for the duration of the computation) there's almost no fork overhead. So, I'd prefer you to ease up on the harshness of your criticism. You may be right. But neither of us know, do we?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.