开发者

Differences between Go and Cython [closed]

开发者 https://www.devze.com 2022-12-11 08:39 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses开发者_运维技巧 on one problem only b
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses开发者_运维技巧 on one problem only by editing this post.

Closed 5 years ago.

Improve this question

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?


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).


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


Differences? Pretty much everything!

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


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.


GO introduces goroutines and channels. See language FAQ


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消