8 ms·
Meet Crystal language in its birthday. It is compiled and has ruby like syntax
- tbrock 13y agoThis is great. Now if we need parallelism we can choose Rubinius and if we require raw speed we can choose Crystal (when it's done) instead of jumping on the JRuby bandwagon. I respect Charles Oliver Nutter but Java is something I want less of in my life. This seems like a great alternative for people seeking performant Ruby interpreters.
- untothebreach 13y agoThis isn't a Ruby interpreter
- NDT 13y agoHow is this different from Ruby?
- scotth 13y agoIt's compiled and type-checked.
- ser0 13y agoWhich also implies performance benefits over Ruby. I think another way to view it is Go with Ruby syntax (although Go has its own runtime overhead). Their introduction document [1] is a pretty concise overview. I think it's an interesting project. But not being a Ruby focused coder these days, I can't see myself choosing this over other compiled languages at this point. [1] https://github.com/manastech/crystal/wiki/Introduction https://github.com/manastech/crystal/wiki/Introduction
- jsnk 13y agoIt doesn't attempt to be different from Ruby at least in its looks and feel. Crystal strives to be as similar to Ruby as possible. The creator stated some reasons why they created Crystal on the github repo. https://github.com/manastech/crystal#why https://github.com/manastech/crystal#why
- continuations 13y agoCan it use Ruby libraries? People use Ruby mostly because of its ecosystem.
- vinceguidry 13y agoIt appears to have nothing to do with Ruby except syntax similarities.
- ddfreyne 13y agoThere is a typo: foo2.ord in the first class Foo(T) example should be foo2.value.ord.
- asterite 13y agoThanks, I just fixed the example.
- gregwebs 13y agoThis is really interesting. A hypothesis I have on Ruby is that people attribute dynamic typing to it being a productive language, but that Ruby is actually productive for other reasons, in spite of being dynamically typed. With Crystal, at least when it matures a bit more, this hypothesis could be tested. There are very logical reasons why dynamic typing at first appears better than static for Rubyists, that I think don't hold up as well after you scratch the surface: * many Rubyists came from Java, and that kind of typing does slow you down. You need a modern type system with at least local type inference (Crystal seems to have global type inference) * dynamic typing does actually help develop things more quickly in some cases, definitely in the case of small code bases for newer developers. A developer only has to think about runtime. With static typing a developer also must think about compile-time types, which takes time to master and integrate into their development. The relative payoff of preventing bugs grows exponentially as the complexity of the code base increases and at least linearly with size of the code base.
- JoshTriplett 13y ago> A hypothesis I have on Ruby is that people attribute dynamic typing to it being a productive language, but that Ruby is actually productive for other reasons, in spite of being dynamically typed. That has always been my reaction to most comments about dynamically typed scripting languages, including Python and Ruby. Most of the time, turning compile-time type errors into runtime exceptions is not a feature.
- vinceguidry 13y agoI'm putting my faith in Ruby. It might take 10 years, but eventually the performance will resemble C's. It's basically a compile-to-C language right now as it is. There's just a whole bunch of inefficiencies in the implementation. Once they get ironed out, we'll finally be able to have our cake and eat it too. One language to rule them all.
- octo_t 13y agoNo it won't. There are so many problems with trying to get a dynamic language like ruby to be in the same order of magnitude of performance as C. Garbage collection, inlining virtual calls etc.
- melling 13y agoGo has garbage collection and it's in the same order of magnitude as C. In fact so are Scala and Java. So, we can at least stop blaming gc.
- andrewvc 13y agoYes, but neither language is nearly as dynamic as ruby. That's where the costs come in. Method calls in ruby are comparatively glacial in speed.
- vinceguidry 13y agoThat's why the ten years.
- blah32497 13y agoAnother language with un-googleable name.
- colanderman 13y agoCan't be worse than Why. (Go ahead, I dare you to find it!)
- andrewflnr 13y agoWow. You have to quote "the why programming language" before you even get a trace. It's not even in wikipedia's alphabetized list.
- hcarvalhoalves 13y agoInteresting. I really liked the solution for writing C bindings. Given the syntax looks similar, could it run Ruby source, unaltered?
- spoiler 13y agoSome of it, I guess. Sometimes it would break due to "type differences," I guess.
- nwmcsween 13y agoYou cannot have full classical OOP with C like performance. It won't happen without a big fat JIT runtime and more optimization than put into hotspot.
- theseoafs 13y agoI was very excited by this when I read the description, because a compiled language that looks like Ruby is exactly what I've wanted. Unfortunately I'm not super excited by the quirks of the implementation. For example: if some_condition a = 1 else a = 1.5 end If I'm working in a compiled and typed language, the last thing I want is a language that automatically gives union types to variables. As far as I'm concerned, the type inference should fail at this point. In the above example, now I'm forcing the compiler to maintain a union which is going to have a pretty significant overhead on every computation the variable `a` is involved in.
- hrjet 13y agoBut isn't that how type inference works in most statically typed languages? For example, in Scala: val x = if (some_condition) Employer else Employee If Employer and Employee both derive from Person, then x will be of type Person. The run time uses dynamic dispatch to figure out how members are accessed from x. If you want to constrain x, you need to specify the type explicitly.
- justinpombrio 13y agoYour example shows a different kind of behavior than the parent's example. A union type (t1 \/ t2) is a type that says "either this value has type t1, or it has type t2". In your example, the type of x is not (Employer \/ Employee), it is their shared superclass - Person. The analogous example would be if val x = if (some_condition) Employer else Employee succeeded even though Employer and Employee did not share a superclass. Very few languages use union types - Typed Racket comes to mind, and Algol apparently did too.
- asterite 13y agoBut actually in Crystal you will have the same behaviour: class Person end class Employer < Person end class Employee < Person end x = some_condition ? Employer.new : Employee.new # x is a Person+ This is not said in the "happy birthday" article (or anywhere else, IIRC). In the beginning we typed x as Employer | Employee. But, as the hierarchy grew bigger compile times became huge. Then we decided to let x be the lowest superclass of all the types in the union (and mark it with a "+", meaning: it's this class, or any subclass). This made compile times much faster, and in most (if not all) cases this is what you want when you assign different types under the same hierarchy to a variable. What this does mean, though, is that the following won't compile: # Yes, there are abstract classes in Crystal abstract class Animal end class Dog < Animal def talk end end class Cat < Animal def talk end end class Mouse < Animal end x = foo ? Dog.new : Cat.new x.talk # undefined method 'talk' for Mouse That is, even though "x" is never assigned a Mouse, Crystal infers the type of "x" to be Animal+, so it really doesn't know which types are in and considers all cases. Again, this is most of the time something good: if you introduce a new class in your hierarchy you probably want it to respond to some same methods as the other classes in the hierarchy.
- spoiler 13y agoIt would be really cool if one could write binary extensions/gems for Ruby with Crystal somewhere down the line... far down the line, probably.
- asterite 13y agoYes, it's one of our dreams too. Right now you can do: # In a foo.cr file fun init_foo = Init_foo : Void puts "Init foo! :-)" end Compiling it: bin/crystal foo.cr -o foo.bundle Then in Ruby: $ irb irb(main):001:0> require "./foo" Init foo! :-) => true But more complex things don't work right now (because of the initial implementation of the GC, which needs to be turned off for this case). So, yes, we are not that far from allow you to write Ruby extensions in Crystal. We'd also like to write Objective-C code that way, and also Erlang extensions.
- lloeki 13y agoThe one that caught my eye is that the macros are disappointing: they merely feel like (not even glorified) syntactic sugar for an eval wrapped in a function. Hint: if I'm manipulating/interpolating a string, it's an eval, not a (lisp-y) macro.
- saljam 13y agoI guess it's also worth mentioning Mirah, a JVM language heavily inspired by Ruby. Unlike JRuby, it compiles down to byte code ahead of time and needs not support libraries. http://www.mirah.org http://www.mirah.org
- saljam 13y agoI guess it's also worth mentioning Mirah, a JVM language heavily inspired by Ruby. Unlike JRuby, it compiles down to byte code ahead of time and needs not support libraries. http://www.mirah.org http://www.mirah.org
- cmollis 13y agoDynamic typing is simply sugar. It's a bit misleading (particularly for newer developers) that you don't have to think about types just because you don't have to declare them. Automatic coercion, etc, is really only useful if you're a more experienced developer because for the most part, you keep the type information in your head. That said, python is the most productive language I've used so far but type management is really just one part of that.
- deleted 13y ago[deleted]
- grandalf 13y agoLooks very interesting. I am intrigued by the idea of Ruby having type hinting and optimizations based on hints.
- ddebernardy 13y agoOne of Ruby's benefits is UTF-8 support for strings. C-strings make it seem it's absent. Or did I missunderatand?
- asterite 13y agoThe current String implementation is just a temporary one. UTF-8 will be there.