Go和Cython之间的区别

huangapple go评论110阅读模式
英文:

Differences between Go and Cython

问题

今天我的一个好朋友问我最新的Go语言和Cython之间的主要区别是什么,Cython是Python的一组C扩展。我对Python了解不多,有人能告诉我为什么Go比Cython好/不好吗?

英文:

Today a great friend of mine asked me what are the main differences between the newest Go language and Cython, which is a set of C-extensions for Python. I don't have much knowledge on Python, can anyone tell me why Go is better/worse than Cython?

答案1

得分: 9

Cython并不是传统意义上的一种语言。它是用于构建Python扩展的预处理器,采用类似Python的语法(实际上,它们力求实现完全的Python兼容性),并生成C代码(使用Python C API)。通过这样做,他们能够包含一些特殊情况的优化,但真正的好处是当您添加Cython特定的静态类型信息时,这些信息将被合并到C代码中,绕过Python运行时进行这些操作,从而实现高速提升。

Go是一种编译型编程语言。在Go中,首先可以生成一个不包含Python运行时/启动Python解释器的可执行文件,而在Cython中这是不可能的。(可能从技术上讲是可能的,但如果您不使用Python,使用Cython就没有意义)。由于Cython只是生成C代码,所以您在评论中的大部分问题并不适用 - 您可以使用任何C调试器(尽管作为Python扩展的事实会使事情变得稍微复杂一些)。

英文:

Cython isn't really a language in the conventional sense. It is a preprocessor for building Python extensions that takes Python-like syntax (actually they strive for full Python compatibility) and produces C code (using the Python C API). Doing this they are able to include some special case optimisations, but the real benefits come when you add Cython specific static type information which is incorporated into the C code, bypassing the Python runtime for those operations and resulting in a high speed up.

Go is a compiled programming language. The first thing that can be done in Go is producing an executable that doesn't include the Python runtime/start a Python interpreter - this is impossible in Cython. (May not be technically impossible - but there is really no point to use Cython if you are not working with Python). Since Cython just produces C most of your questions in the comment don't really apply - you can use any C debugger (although the fact that's a Python extension makes things a bit more complicated).

答案2

得分: 5

gevent是一个并发库,其核心使用Cython。它似乎非常快速:http://nichol.as/asynchronous-servers-in-python

英文:

gevent is a concurrent library that uses Cython at its core. It seems to be pretty fast: http://nichol.as/asynchronous-servers-in-python

答案3

得分: 4

差异?几乎是一切!

  • 并发和通道。
  • 接口。
  • 静态类型检查。
  • ...
英文:

Differences? Pretty much everything!

  • Concurrency and channels.
  • Interfaces.
  • Static typechecking.
  • ...

答案4

得分: 2

关于支持方面,你依赖于Google提供的单一编译器。如果Go倒闭或转为商业化,那该怎么办呢?

使用Cython,如果Cython项目倒闭,你总是可以回到Python(或者将C代码移植)。

更新:我必须说我现在对Cython感到不满。 缺乏线程支持 是一个重大打击。Cython是线程安全的,但代价很高。全局解释器锁在函数执行期间一直被持有,从而禁用了整个代码库的并发执行!

Cython的C语言特性文档不完善,对初学者来说很令人困惑。我承认。

Cython的目的是支持Sage数学软件;Go的目的是支持Google对尖端昂贵硬件的雄心勃勃计划。

简而言之,我不再喜欢这两种语言。我要回到C++(再次)。我最喜欢的是Cython

英文:

What about support. You are relying on a single compiler, provided by Google. What if Go folds or goes commercial?

With Cython you could always go back to Python (or port the C code) if the Cython project folded.

UPDATE: I must say that I am now upset with Cython. The lack of thread support is a major blow. Cython is thread-safe BUT at a serious cost. The global interpreter lock is held the whole time a function executes. Thereby disabling concurrent execution over an entire codebase!

Cython's C-like features are poorly documented and confusing to novices. I admit.

Cython's purpose is to support the Sage mathematics software; Go's is to support Google's ambitious plans for cutting-edge expensive $$ hardware.

In short, I no longer like either one of these languages. Going back to C++ (again). My favorite is Cython.

答案5

得分: 1

GO引入了goroutines和channels。请参阅语言FAQ

英文:

GO introduces goroutines and channels. See language FAQ

答案6

得分: 1

我尝试使用Go的主要原因是它被认为很容易将并发引入程序中。我认为这将是“下一个大事”,因为处理器速度将会减慢,而且越来越多的多核处理器可用。如果你想利用多核处理器,你需要编写能够并发运行的程序。

我之前看过Erlang,但尽管我习惯于Prolog,我仍然觉得它有点奇怪;它与你所熟悉的“普通”编程语言(如C或Pascal系列)非常不同。但一旦你掌握了它,它的并发特性就很容易使用。我只需付出很少的努力,就能编写一个并行解析器,它不使用堆栈,而是每次有多个选项时生成一个新的“线程/进程”。

到目前为止,Go看起来还不错,尽管有一些轻微的不一致之处。而且它也很快,这是一个额外的好处。

所以,除非Cython也能使并发变得容易,否则我更喜欢Go...

英文:

My main reason for trying out go is the supposed ease of introducing concurrency into programs. I think that will be the 'next big thing', as processor speeds will tail off, and increasingly multiple cores are available. If you want to make use of multicore processors, you need to write your program so that it can run things concurrently.

I earlier looked at Erlang, but despite being used to Prolog I find it a bit strange still; it is so different from your 'average' programming language (of the C or Pascal family). But its concurrency features are easy to use, once you get the hang of it. With very little effort I was able to write a parallel parser, which does not use a stack, but spawns a new 'thread/process' every time there were multiple options.

So far go looks quite alright, despite some slight inconsistencies. And it's also fast, which is a bonus.

So unless Cython also makes concurrency easy, I'd favour go...

huangapple
  • 本文由 发表于 2009年11月17日 01:12:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/1743526.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定