就像 Java 之于 Scala 一样,C++是为了……?
虽然 C++0x 相对于 C++ 有相当大的改进(类型推断、匿名函数等等),但我不得不说 Scala 似乎更好。问题是 Scala 只能运行在 JVM 上,尽管它似乎也可以运行在 C# 之上。
理想情况下,我想要一种像 Scala 一样好的语言,但运行在 C++ 之上——使用标准库,轻松链接到 C/C++ 目标文件,整个过程。我做了很多基于完善的 C/C++ 库(快速且可靠)构建的数值编程,这不是我可以放弃的。
有人知道这样的语言吗?
更新:
我正在寻找的功能是:
与C/C++库无缝集成,就像Scala可以访问Java库而无需生成/维护绑定
一个强大的类型系统,具有设计良好的类型推断系统,使我不必编写冗长和冗余的类型注释
语言内置的函数式和面向对象功能,具有自己的库的支持,而不是仅依赖于标准 C/ C++ 库。
看起来现在正在完成的许多 clang/LLVM 工作可能会促进这些方面的工作,但很高兴发现类似的事情已经在进行中。
Although C++0x is quite an improvement to C++ (type inference, anonymous functions, and so on), I have to say that Scala seems even better. The thing is that Scala only runs on the JVM, although it seems like it can also run on top of C#.
Ideally, I would like a language as nice as Scala, but running "on top of" C++ -- using the standard libraries, easily linking against C/C++ object files, the whole deal. I do a lot of numerical programming built of top of well established C/C++ libraries (fast and reliable), and that is not something I can walk away from.
Is anyone of aware of such a language?
Update:
The features I am looking for are:
Seamless integration with C/C++ libraries, just like Scala can access Java libraries without the need for bindings to be generated/maintained
A strong type system, with a well designed type inference system that keeps me from having to write verbose and redundant type annotations
Functional and OO features built into the language, with the support of its own libraries instead of only relying on the standard C/C++ libraries.
It seems like a lot of the clang/LLVM work being done right now may facilitate work along these lines, but it would be nice to find that something like this is already being worked on.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
这个问题发布已经有几年了,但 C++14 现在可能是正确的答案。 C++11/14 添加了类型推断、lambda 函数以及类似于在 Java 上添加的 Scala 的各种其他功能。 C++98/03 替代品的其他现实竞争者是 Go 和 Rust。
It's been a few years since this question was posted, but C++14 is probably the right answer now. C++11/14 add type inference, lambda functions, and various other features akin to those Scala added over Java. Other realistic contenders for a C++98/03 replacement are Go and Rust.
我想知道为什么还没有人提到D 编程语言。它非常适合您的要求。
I wonder why no one has yet mentioned the D programming language. It is a perfect fit for your requirements.
您可能想考虑 Haskell。它与任何语言一样优秀(当然,以它自己的方式),但它热衷于函数式编程,因此学习障碍很大。尽管如此,它仍然可以用来调用 C/C++,而且它本身的性能令人惊讶。
您还应该决定是否需要语言本身具有相当高性能的计算能力。如果没有,创建与 C/C++ 的 Python 绑定非常容易,并且 Python 有很多不错的功能。或者您可以使用 Matlab 之类的东西,它是为数值计算而设计的,我相信您很清楚,并且可以通过 mex 文件与 C 代码很好地集成。如果您确实需要一种当前可以编写高性能代码的语言,您甚至可以考虑承担为 Scala 创建 C++ 绑定的重要任务(如果您使用Java 的 JNI 或 JNA,然后从 Scala 调用 Java),然后仅将其用于最重要的数字工作,而 Scala 处理时间要求不那么严格(但仍然有些重要)的部分。
You might want to think about Haskell. It has as much niceness as any language out there (in its own way, of course), but it is ardent in its adherence to functional programming so the barrier to learning is substantial. Still, it can be used to call C/C++, and it's surprisingly high-performance on its own.
You also should decide whether you need the language itself to be capable of fairly high-performance computing. If not, it's pretty easy to create Python bindings to C/C++, and Python has quite a few nice features. Or you could use something like Matlab, which is designed for numeric computing as I'm sure you well know, and can integrate with C code pretty well via mex files. If you do need the language to be one in which you can currently write high-performance code, you might even consider taking on the nontrivial task of creating C++ bindings for Scala (it's not that bad if you use JNI or JNA for Java, and then call that Java from Scala), and then only use that for the most important numeric work while Scala handles the less time-critical (but still somewhat important) parts.
编写与 C++ 兼容的语言很困难,因为它的功能太多,而且 ABI 通常被认为是特定于特定版本的 C++ 编译器的。如果您确实正在寻找与 C++ 的简单集成,我敢说您最好的选择是将 Scala 与 GCJ 结合使用。您可以使用 GCJ CNI 与您的 C++ 对象集成(尽管建议GCJ CNI 是在这里投反对票的理由。)
It's hard to write a language that's compatible with C++, becuase there are so many features, and the ABI is generally considered to be specific to a particular version of the C++ compiler. If you're really looking for easy integration with C++ I'd venture that your best bet is to use Scala with GCJ. You can use the GCJ CNI to integrate with your C++ objects (though suggesting the GCJ CNI is grounds for a downvote around here.)
Scala 本身怎么样,通过 SWIG 生成的 Java 绑定访问您的 C++ 库?
How about Scala itself, with access to your C++ libraries through SWIG-generated Java bindings?
我很惊讶没有人提到D。它接近 C++ 语法,但更“干净”,可以毫无问题地使用 C 和 C++ 库,并添加了许多高级功能。当然,这一步不像从 Java 到 Scala 那么大,但我认为考虑到 C++ 的复杂性,想出一个真正创新的设计而不抛弃 C++ 的大部分部分要困难得多。
I'm surprised nobody mentioned D. It is close to the C++-syntax but much "cleaner", can use C and C++ libs without problems and adds a lot of advanced features. Sure, the step is not as big as from Java to Scala, but I think given C++'s complexity it is much harder to come up with a really innovative design that doesn't throw most parts of C++ away.
Scala 是一种面向对象的函数式编程语言。如果您正在寻找一种现代的面向对象和函数式编程语言,并且还可以通过外部函数接口调用 C 代码,那么您可能会对 OCaml。
Well, Scala is an object-oriented and functional programming language. If you are looking for a modern object-oriented and functional programming language that can also call C code through a foreign function interface, then you might be interested in OCaml.
Rust 看起来是一个越来越好的候选者。
Rust is looking like a better and better candidate.
Python 与 C++ 绑定怎么样?
请参阅此处。
What about Python with C++ bindings?
See here.
Scala + JNA 怎么样?基本上,JNA 是一个库,允许您声明与 DLL 匹配的接口(或 Scala 中的特征)。
How about Scala + JNA? Basically, JNA is a library that allows you to declare interfaces (or traits in Scala) that match DLL's.
看看:
D 编程语言
Have a look :
D Programming Language
我正在寻找同样的东西。 Lua和D是两个选项。 lua 有一个命令行解释器,luajit 速度很快,对于数学我使用 gsl shell。 D 更复杂,但仍然易于使用。 D 也和 C++ 一样快。
I'm looking for the same thing. Lua and D are two options. lua has a command line interpreter, luajit is fast, and for math I use gsl shell. D is more sophisticated but still simple to use. D is also as fast as C++.