简体   繁体   English

哪种动态语言可以轻松使用其他语言的库?

[英]Which dynamic language can easily use libraries from other languages?

Tell why you think Python, Perl, Ruby, etc is easiest for plugging in modules from other languages with minimal thought. 告诉您为什么您认为Python,Perl,Ruby等最容易从其他语言插入其他语言的模块。

To clarify, an example: I want to write business logic in Python, but use functionality that conveniently exists as a Perl module. 举例说明:我想用Python编写业务逻辑,但要使用作为Perl模块方便存在的功能。

In other words, which language "just works" with the most modules? 换句话说,哪种语言最适合大多数模块?

Perl has very good support for other languages via the Inline set of modules. Perl通过内联模块对其他语言有很好的支持。

Inline::Python allows you to import Python modules, classes and functions into your Perl code and call them from Perl as if they were native - see Importing Functions . Inline :: Python允许您将Python模块,类和函数导入到您的Perl代码中,并从Perl中调用它们,就好像它们是本机的一样-请参见导入函数

Inline::Ruby works virtually the same way. 内联:: Ruby几乎以相同的方式工作。

The Parrot VM looks like the way to go for this purpose, since 出于以下目的, Parrot VM看起来像是要走的路,因为

Parrot currently hosts a variety of language implementations in various stages of completion, including Tcl, Javascript, Ruby, Lua, Scheme, PHP, Python, Perl 6, APL, and a .NET bytecode translator Parrot当前在完成的各个阶段托管各种语言实现,包括Tcl,Javascript,Ruby,Lua,Scheme,PHP,Python,Perl 6,APL和.NET字节码转换器

It matters less, I think, which of these languages you use as the "main driver" and which one just as "guests" for this module or that -- just check that you pick one whose Parrot implementation is complete and mature (since Parrot's a rather new project, and so are some of these language implementations on top of it). 我认为,使用这些语言中的哪一种作为“主驱动程序”,使用哪种语言作为该模块的“来宾”,或者-仅检查您选择其Parrot实现完整且成熟的一种语言就可以了(因为Parrot的一个相当新的项目,最重要的是这些语言的实现)。

If you want to plug in a Perl module, the language which is best suited for this is Perl. 如果要插入Perl模块,则最适合此的语言是Perl。 Perl is able to represent the semantics and capabilities of code written in Perl correctly. Perl能够正确表示用Perl编写的代码的语义和功能。 This really shouldn't be a shock. 这真的不应该让人感到震惊。

If you have a self-contained program you want to call from another program in its own process, not constantly interacting, any of these languages can do that with programs written in whatever language. 如果您有一个独立的程序,并且希望在另一个程序中以自己的方式调用它,而又不经常交互,则这些语言中的任何一种都可以使用以任何语言编写的程序来实现。 At that point, you aren't really using other languages inside a program but just calling other problems. 那时,您实际上并没有在程序中使用其他语言,而只是在调用其他问题。

There are several projects to combine various pairs and projects (like Parrot) that seek to provide a platform for a large range of languages for compatibility and projects (like .NET) that almost accidentally provide compatibility among previously-incompatible languages. 有几个项目将各种对和项目(例如Parrot)组合在一起,这些项目和项目试图为多种语言提供兼容性平台,而项目(.NET)几乎偶然地提供了以前不兼容的语言之间的兼容性。 However, I do not think most of these are as robust, mature, and suited for combining normal code as you would hope. 但是,我认为其中大多数都不像您希望的那样健壮,成熟并且适合于组合普通代码。

all 3 languages have very good, clear facilities for just calling any executable in a subprocess (including executables like python somethingelse.py or ruby somethingelse.rb ). 所有这三种语言都具有非常好的,清晰的功能,可用于仅在子进程中调用任何可执行文件(包括python somethingelse.pyruby somethingelse.rb类的可执行文件)。

use what you know best. 使用您最了解的内容。

I'm going to answer on a more architectural level here. 我将在这里在更多的体系结构层面上回答。 The question is what are you trying to do... do you want to write your business logic in Python and call a Perl function from Python? 问题是您要做什么...您要用Python编写业务逻辑并从Python调用Perl函数吗? Or are you looking to execute a script? 还是您要执行脚本? If so, how will the two communicate? 如果是这样,两者将如何沟通?

I suspect, but don't know, that Parrot VM might allow you to do that, but as Mike points out, there are difficulties. 我怀疑,但不知道,Parrot VM可以允许您这样做,但是正如Mike指出的那样,存在很多困难。 Cross-language work is hard just like IPC across programs is hard unless you use some form of loose coupling (not so tied to the language). 跨语言的工作很困难,就像跨程序的IPC很难一样,除非您使用某种形式的松散耦合(与语言无关)。 To that end, you might consider setting up the controller in one language and having everyone else talk via a dbus queue, or whatever mechanism you prefer for whichever platform you're on. 为此,您可能会考虑以一种语言设置控制器,并让其他所有人通过dbus队列或您所使用的平台所喜欢的任何机制进行交谈。 It doesn't really matter how you do it (cue a debate on the best mechanism) but properly designed it makes talking across languages and building plug-ins very easy. 怎么做并没有关系(有关最佳机制的辩论),但经过适当设计,它使跨语言交谈和构建插件非常容易。 For example, you might have a queue for process_new_user , for example. 例如,您可能有一个process_new_user队列。 Any script who registers in that queue gets access to the data so a new developer can easily add functionality for their part of the program. 在该队列中注册的任何脚本都可以访问数据,因此新开发人员可以轻松地为其程序部分添加功能。 Interpret that as: you can easily use a different scripting language to implement that bit. 解释为:您可以轻松地使用其他脚本语言来实现该功能。

The Dynamic Language Runtime was specifically designed to allow one dynamic language to use objects and functions defined in another dynamic language. 动态语言运行时经过专门设计,允许一种动态语言使用另一种动态语言中定义的对象和功能。 Currently Python and Ruby have DLR implementations, but I haven't heard anything about Perl. 目前,Python和Ruby具有DLR实现,但是我还没有听说过有关Perl的任何信息。

To use the DLR you need either .NET or Mono. 要使用DLR,您需要.NET或Mono。

Most scripting languages can handle this kind of thing (by running external programs written in other languages,) but it seems as if your best bet might be shell scripting of some kind (Windows users call this "batch scripting," but the DOS syntax is horrible and not recommended.) UNIX programmers have been freely mixing languages in this way for a long time. 大多数脚本语言都可以处理这种事情(通过运行用其他语言编写的外部程序),但是最好的选择似乎是某种形式的Shell脚本(Windows用户将此称为“批处理脚本”,但是DOS语法是UNIX程序员很长时间以来一直以这种方式自由地混合语言。 On Windows, you can install Cygwin to get a fully functional BASH shell. 在Windows上,您可以安装Cygwin以获得功能齐全的BASH Shell。

The shell was originally intended as a user interface, used to launch other programs or combine them in interesting ways. 该外壳最初旨在用作用户界面,用于启动其他程序或以有趣的方式组合它们。 However, many shells (notably the Bourne shell or its modern descendant, BASH) are also fully-fledged programming languages. 但是,许多外壳程序(特别是Bourne外壳程序或其现代后代BASH)也是成熟的编程语言。 Each of your "modules" can be created as separate, standalone programs which will be run by the shell script. 可以将每个“模块”创建为单独的独立程序,这些程序将由Shell脚本运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 任何可以使用c库的高级语言? - Any high-level languages that can use c libraries? 我可以在Android Dalvik上使用哪些编程语言? - Which programming languages can I use on Android Dalvik? 可以使用其他编程语言的Mathematica(python / C#)吗? - Possible to use Mathematica from other programming languages (python/C#)? 我可以使用msilib或其他Python库从.msi文件中提取一个文件吗? - Can I use msilib or other Python libraries to extract one file from an .msi file? 我可以使用多种语言的基于Linux的ORM吗? - Can I use a linux-based ORM from multiple languages? 建议使用哪种语言 - Advice on which language to use 如何构造类以使我可以轻松地从使继承对象腌制的“ Persistor”类继承? - How to structure classes such that I can easily inherit from a “Persistor” class which pickles the inherting object? Python用什么工具解析编程语言? - Which tool to use to parse programming languages in Python? 动态库的加载顺序是否重要? - Does the order in which dynamic libraries are loaded matter? 我可以使用依赖于其他库的 kivy 构建 GUI 应用程序吗? - Can I build GUI application, using kivy, which is dependent on other libraries?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM