crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.47k stars 1.62k forks source link

"crystal is to ruby, what cython is for python" -- if it is correct statement, then put it in FAQ documentation , #1717

Closed zaxebo1 closed 9 years ago

zaxebo1 commented 9 years ago

From the first looks on the website, can i say that "crystal is to ruby, what cython is for python" ? If it is right statement then probably it can be put into FAQ, so that programmers coming from python can easily understand the analogous

asterite commented 9 years ago

@zaxebo1 Can cython detect type errors at compile time?

refi64 commented 9 years ago

@zaxebo1 I'm a Python programmer, and that isn't even close. Cython just speeds up Python, with optional type annotations for more speed and the ability to generate Python bindings. Crystal is a completely different language from Ruby that happens to share syntax and some design concepts but is still very different. I'm not a Ruby fan, yet I really like Crystal.

It's more like Crystal is to Ruby as the late Wirbel is (was?) to Python.

bcardiff commented 9 years ago

The first two statements in http://docs.cython.org/src/quickstart/overview.html do not match crystal

Cython is a programming language that makes writing C extensions for the Python language as easy as Python itself.

Crystal is based on Ruby syntax, but does not aim to be a tool. There are some experiments to expose native extensions to ruby programmed in crystal, but that is as match as it's get right now.

It aims to become a superset of the Python

Noup. Crystal does not aim to be a superset of Ruby.

zaxebo1 commented 9 years ago

Thanks for replying. I am gladly surprised at such a fast response, this positively means that community of this is very active.

1) @asterite : cython can detect type errors

2) @bcardiff : it is superset of python, only in the sense that although pure python scripts can be compiled by cython easily, but if you mark types with cython specific annotations, then the types will be taken from those programmer-specified additional annotations and keywords. Only this superset thing for typing - is there. BUT still this superset keywords is just for sugar syntaxing, i can put the same extra superset keywords also in perfectly valid python annoations, and it will become perfectly valid python program also.

METHOD1 to use cython: cython operating as it is on a python program

pure python code like this , can be compiled by cython to native executable

import cython b1=10 print(10) print(type(b1))

METHOD2 to use cython : cython giving superset features for aid in type derivation and speeding up things. This superset "cdef" keyword here is not compatible with python

superset cython code(extended via a new keyword "cdef" here) can be compiled by cython to native executable

import cython cdef int b1 b1=10 print(10) print(type(b1))

METHOD3 to use cython : cython specifying the same type information in python syntax, so the same program becomes portable to cython and pthon both, but is still type annotated by programmer.

this example runs on python and cython both. "cdef" is converted to "cython.declare" here

import cython b1=cython.declare(cython.int) b1=10 print(10) print(type(b1))

SIDE NOTE: that now just few weeks back released version 3.5 of python itself contains core language contructs for specifying type constructs of function parameters etc

zaxebo1 commented 9 years ago

or, may be its not 100% analogous, but now my modified proposed FAQ statement(for python programmers) can be : "in some use cases, crystal and cython are analogous. "

refi64 commented 9 years ago

Not even that. Cython is still mostly Python. Crystal isn't exactly even trying...

zaxebo1 commented 9 years ago

@kirbyfan64:

1) so are you saying that ?? - "not every ruby syntax is supported by crystal", .? OR, 2) so are you saying that ?? - we can not call ruby third party libraries into crystal directly.? (this is very important for me, to know) OR, 3) so are you saying that ?? - crystal standard library and ruby standard library have incompatibilities?

asterite commented 9 years ago

@zaxebo1 Crystal is a new language with Ruby-inspired syntax. It's not Ruby, it's not a Ruby implementation, it won't run Ruby programs, etc.

zaxebo1 commented 9 years ago

ohh.. okk

waterlink commented 9 years ago

@zaxebo1

  1. Yes, not every ruby syntax is supported.
  2. Yes, you can not call any ruby program with crystal (actually most of them will require some changes).
  3. Yes, stdlibs have incompatibilities.

Best Regards, Alexey Fedorov, Sr Ruby, Clojure, Crystal, Golang Developer, Microservices Backend Engineer, +49 15757 486 476

2015-10-10 2:03 GMT+02:00 zaxebo1 notifications@github.com:

ohh.. okk

— Reply to this email directly or view it on GitHub https://github.com/manastech/crystal/issues/1717#issuecomment-147014070.

refi64 commented 9 years ago

@zaxebo1 Yes, yes, yes. In my mind, this is a good thing, since Crystal also tries to avoid aliases, which is also what Python does.

zaxebo1 commented 9 years ago

ok permit me ask a one final question in other dimension:

1) Do ruby and crystal share "enough common things", that I can write a non-trivial sufficiently complex program from scratch in "that COMMON SUBSET of crystal and ruby", so that the program can run both on ruby and crystal. 1.a) non-trivial program (written in some common subset) to perform scientific manipulation 1.a) non-trivial program (written in some common subset) to perform RDBMS access and take input and display on web

Is it possible?

2) In this common subset(of crystal and ruby), can there be some kind of if-else kind of statement(preprocessor statement or part of language construct etc), so that the incompatible libraries call between ruby and crystal can be put it in conditional block, like:

if lang() == "crystal" CrystalStdlib_FunctionCall() else RubyStdlib_FunctionCall() end

refi64 commented 9 years ago

It's about as possible as trying to write C++ and C# together...

Crystal requires type annotations in a few places that Ruby would consider syntactically invalid (e.g. [] of Int). I would consider it possible, but jt would be kind of suicidal. :O

Trust me: just use Crystal. It's a good 200x better than Ruby.

technorama commented 9 years ago

Has anyone considered pushing to allow crystal type annotations in ruby? The stdlib is semi compatible but could be made more compatible by providing additional libraries.

zaxebo1 commented 9 years ago

@technorama :
your suggestion is really good/ just alternative wild suggestion from my side.

in cython , the types can be written using "cdef" as "import cython cdef int b1"

But types can also be written in python compatible syntax using "cython.declare()" such as: ""import cython b1=cython.declare(cython.int)""

in the same way, we can put ruby compatible syntax alternative for putting crystal type annotations in crystal programs. This minimal compatibility will make it attractive for large number of ruby developers

waterlink commented 9 years ago

@zaxebo1 Crystal team made a decision not to be Ruby compatible to cast off all the bad baggage that Ruby has. I would say, if you want to write the same programs for ruby and crystal - it will never happen.

Best Regards, Alexey Fedorov, Sr Ruby, Clojure, Crystal, Golang Developer, Microservices Backend Engineer, +49 15757 486 476

2015-10-10 8:30 GMT+02:00 zaxebo1 notifications@github.com:

@technorama https://github.com/technorama :

just a wild suggestion.

in cython , the types can be written using "cdef" as "import cython cdef int b1" But they can also be written in python compatible syntax using "cython.declare()" such as: ""import cython b1=cython.declare(cython.int)""

in the same way, we can put ruby compatible syntax alternative for putting crystal type annotations in source. This will make it attractive for large number of ruby developers

— Reply to this email directly or view it on GitHub https://github.com/manastech/crystal/issues/1717#issuecomment-147045595.

jhass commented 9 years ago

I think the question is sufficiently answered with no, closing.

Zhomart commented 7 years ago

I'd say "Crystal is for ruby" is the same as "Nim is for python".

shayneoAtNorwood commented 7 years ago

Totally different beasts. The Nim/Python comparison is much closer. cython is primarily aimed at speeding up python by letting you compile modules and classes t no C which is then transnogrified into ruby, which can be quite dramatic if you use the optional type annotations. However the super duper dynamic nature of python (And ruby) means that without the type annotations you end up with C that has to do a lot of faffing around with its introspection to run so while faster than cpython, its still not as fast as we'd want it. Crystal , while having more than a passing resemblance isn't ruby, nor is it ruby+types. Its a completely different language That relates to ruby in the way that, say , modula-2 relates to pascal. Close, but not quite. I'd say its closest analogue is actuall Go, but with safer types aaaand a slightly more immature ecosystem.

However if you know python or ruby, crystal is an afternoon at most to grok.