8 ms·
From Ruby to Crystal: A Quick Look
- nurettin 10y agoGreat writeup for the folks who are curious but lack the time to test Crystal.
- neovintage 10y agoOutside of speed benefits as compared to ruby, one of the main things going for crystal is it's ability to use all of the robust tooling that already exists. This post mentions it in passing but Crystal gets the benefit of all the existing tooling without having to build it as part of delivering the language to developers. I think that's a huge win. I also think this is one reason why Crystal has grown fairly quickly. This could largely but due to the fact that it's built upon LLVM. Regardless, the community and documentation is pretty awesome. I can't wait to see what happens for the 1.0 release.
- xtracto 10y agoCan you be more specific on what you mean about "existing tooling"?. I work in a Ruby shop and am very curious to try Crystal.
- deedubaya 10y agoCrystal could be a really powerful tool for enhancing existing Ruby code. Imagine a world where you write your code in Ruby, but farm out the expensive operations to a Ruby-like Crystal extension (similar to what is commonly done with C or Rust). I think this is possible already (just after a quick Google search[1]), just not friendly for the average Ruby dev to implement. [1] https://www.slideshare.net/AnnaKazakova/how-to-write-ruby-extensions-with-crystal https://www.slideshare.net/AnnaKazakova/how-to-write-ruby-ex...
- shawn42 10y agoNeat. Thanks for posting that. Hopefully, that process could be cleaned up and streamlined as a lot of it would be repetitive boiler plate.
- prh8 10y agoThis is definitely possible-- I've done even more than basic PoC (Anna's slide deck was one of my starting points in fact). https://github.com/phoffer/crystalized_ruby https://github.com/phoffer/crystalized_ruby
- pjmlp 10y agoWhen I look at Crystal, what comes to my mind is that it is what Ruby could have been if the community had taken Dylan as inspiration in regards to language design and tooling.
- ajamesm 10y ago70x faster? If Crystal gets its own port of Ruby on Rails, oh boy.
- shawn42 10y agoThere are quite a few web frameworks headed in that direction: https://github.com/veelenga/awesome-crystal#web-frameworks https://github.com/veelenga/awesome-crystal#web-frameworks
- vidarh 10y ago70x faster, with the caveat that the way that Ruby code is written really does not lend itself to speed. E.g. using method calls inside the class instead of accessing instance variables instantly springs to mind, as does the "unsorted priority queue" which is basically a horrible abuse of Array but wrapped in a class that makes it even slower by adding additional method calls for every operation. That's not to diminish the speedup Crystal gets, because it does illustrate how slow MRI's method calls are, but it'd be interesting in seeing a comparison with an astar implementation that was actually written to be fast in Ruby. Also would be very interesting to see a comparison with jRuby+Truffle, of course.
- RX14 10y agoCrystal does the same as ruby for instance variable access, it's just that such methods are such an easy target for inlining by LLVM there's practically no performance penalty. The flexibility of gets and sets simply being method calls is very awesome and very worth it.
- vidarh 10y agoIt sounds like more substantial semantic differences then, as in the Ruby case the challenge with making it fast is that you can't take shortcuts like that without first verifying that there are no possible calls to any code that can have side effects like making changes to the receiver - you need to be prepared to "deoptimize" the code back to doing full method calls at any point, as in the general case you have no guarantee that the code will remain a simple getter/setter.
- mnarayan01 10y agoMy biggest takeaway from reading this is that Crystal is much more divergent from Ruby than I expected.
- ricardobeat 10y agoIn fact being similar to or compatible with Ruby is not a language goal at all.
- vidarh 10y agoThat's communicated very poorly, when the first thing on the website is "fast as C, slick as Ruby" followed by mentioning how similar the syntax is to Ruby.
- em77 10y agoI'm getting the impression of a running pattern of argument when talking about Crystal: Crystalist: "Crystal is very Ruby-inspired. Welcome Ruby devs! What makes Crystal great is it's as fast as alternatives to Ruby, without sacrificing Ruby syntax and functionality! Port over your Ruby code! Crystal is Ruby on steroids!" Rubyist: "Why does Crystal diverge from Ruby here, here, and here unnecessarily if the goal is to be similar to Ruby and allow porting more easily?" Crystalist: "Crystal is not Ruby. Crystal has no goal of being similar to Ruby. Any similarity to other languages is purely coincidental. What's Ruby?"
- vidarh 10y agoYes, it feels a bit like a bait and switch to me. I can understand that - I've been tempted to go down the same route myself... But the messaging around it is all over the place. On one hand, when they explicitly state that the goal is not for Crystal to be as close to Ruby as possible, that makes me more sympathetic. At the same time it also makes me less likely to use it anytime soon. Not out of ill will - it's an interesting project and I hope they do well - but hardly any of my Ruby code is CPU constrained, so I have little reason to switch for speed. Had they aimed as close as possible, I might have tried anyway, but every little extra difference makes it less worthwhile. Of course that's very different for people that actually write code where speed is a major concern and that e.g. haven't been able to use Ruby for that reason.