News for hackers. Stuff that matters.
Re:Porting Ruby to Crystal by dopamean on Friday March 10, 2017 @09:51AM (#13838960)
Mike Perham ported some of Sidekiq to Crystal and did brief writeup about it [0]. It'll be interesting to see if this thing really goes somewhere.

[0] http://www.mikeperham.com/2016/05/25/sidekiq-for-crystal/

Re:Porting Ruby to Crystal by pkd on Friday March 10, 2017 @08:52AM (#13838533)
I agree that compile to binary languages are better for distribution, and has always been a pain point with interpreted languages like Ruby. Ruby actually does this better with its ecosystem (RubyGems, Bundler) than a lot of other mainstream languages.

Just to nitpick, capturing STDOUT is not that hard in Ruby at all. Definitely not as easy as Stdio.capture, but Ruby gives you a variable called $stdout, which you can assign to local variable and treat it like a file. If you would rather not print messages out during the test, then you can just temporarily assign $stdout to nil.

Re:Porting Ruby to Crystal by pjmlp on Friday March 10, 2017 @09:55AM (#13838994)
> I agree that compile to binary languages are better for distribution

Personally I think the wide adoption of JVM, CLR, Python, Ruby,..., alongside the demise of languages like Delphi, helped fortify C and C++ place at begining of this century.

For many people, they became the only two languages they knew that were capable of producing binaries, unaware of other options.

Thankfully the tide is turning.

As for Ruby, I always felt the community could have learned from Dylan and implemented a proper AOT compiler, for a while RubyMotion seemed to be that one.

Now we have to bet on Crystal it seems.

Re:Porting Ruby to Crystal by vidarh on Friday March 10, 2017 @02:14PM (#13841179)
> and implemented a proper AOT compiler

Ruby is fundamentally hard to AOT compile efficiently (that's part of the fun I have of trying to compile it...). Part of the challenge is that the moment you allow eval() you have to include a JIT anyway.

Even without it, something as basic as "require" (to load modules/include files) in the typical Ruby install has been overridden by bundler and/or Rubygems to dynamically alter what will get loaded, and e.g. a variety of patterns involve dynamically altering the load path based on directory content.

Something as "simple" as generating a staticaly linked binary out of a Ruby program involves solving the halting problem (e.g. your program could wait for user input to decide which file to load) or making decisions that makes your compiled binary act different to how the interpreter would.

Basically, to statically link Ruby you have pretty much two choices: Make a new language, like Crystal, or determine the minimum set of limitations / changes to Ruby semantics to make it viable to compile with the lowest amount of breakage. I'm trying for the latter, but who knows, something like Crystal might turn out to be the better option. It's certainly a simpler option.

A large part of the problem is that Ruby grew organically based on an interpreter rather than being designed with compilation in mind.

Re:Porting Ruby to Crystal by pjmlp on Friday March 10, 2017 @04:50PM (#13842477)
Yes, chrisseaton answered me about it the other day.

I was telling him that from my point of view, given the work done in languages as dynamic, meaning Lisp, Dylan, Smalltalk, that from my naive of view (I know Ruby only superficially) that could be applied to Ruby as well.

He also answered me along those lines, that idiomatic Ruby abuses more the dynamism than those languages.

Re:Porting Ruby to Crystal by vidarh on Saturday March 11, 2017 @02:42AM (#13844677)
Chris's work is fantastic - I hope I'll eventually get to the stage of doing the same amount of dirty tricks that he's been doing.

I think we can get there eventually with respect to AOT (and frankly Chris is likely to get there first - as much as I have a general aversion to the JVM, the infrastructure they are getting with Truffle/Graal and now Substrate is impressive), but to solve the issue properly will take a lot of heuristics, coupled with getting some kind of agreement on various minor semantic changes to indicate compile time/runtime split.

I also really badly at some point want to analyze a bunch of Ruby code - as in crawl all the Ruby on Github big - to look for things like use of eval(), redefinitions of core methods, weird code loading tricks etc. to get an indication of how these things are actually used. Delineating what people actually do would be a big step forward in figuring out what to do about it...

I suspect, but don't know for sure, that most of the disaster-scenarios we've thought up involving Ruby sees little enough usage outside of people going "look what insane thing I can do with Ruby" that for some it may be better to just break code and fix it.

Re:Porting Ruby to Crystal by ehsanu1 on Friday March 10, 2017 @03:20PM (#13841764)
Yep, JIT is way more viable (and being done) with Ruby.
Re:Porting Ruby to Crystal by vidarh on Friday March 10, 2017 @03:41PM (#13841942)
JIT doesn't the solve the problems people want AOT for, though, including the require/load path issue I mentioned - you still end up having to ship your entire source tree / gem bundles. Which is part of my motivation for still plodding along with my AOT compiler when I have time (the other motivation is that I've learned more about Ruby trying to compile it than I ever would from just "normal usage")
Re:Porting Ruby to Crystal by squar1sm on Friday March 10, 2017 @06:48PM (#13843153)
I probably wasn't being clear about STDOUT on the ruby version. I just didn't do it in this particular project for the ruby version. I just tested that the flags didn't throw anything. I had tests on other production tools and yeah $stdout saving is nice.

Someone mentioned on reddit me about a CLI testing framework that perhaps does a more holistic job of testing STDOUT.

--> https://bitheap.org/cram/

it's written in python but it's not for python projects per se.

Re:Porting Ruby to Crystal by wiremine on Friday March 10, 2017 @11:24AM (#13839729)
If you're a Ruby dev, it's worth your time checking out Crystal. As others have pointed out, it isn't a one-to-one replacement for Ruby, but if you enjoy the Ruby syntax and general way of approaching problems, Crystal is a handy tool.

I've been playing around with it for a a while, and really enjoy it.

That said, if you hate Ruby, keep walking...

Re:Porting Ruby to Crystal by raesene6 on Friday March 10, 2017 @10:45AM (#13839429)
There are some other options for this like Travelling Ruby

http://phusion.github.io/traveling-ruby/

Re:Porting Ruby to Crystal by base on Friday March 10, 2017 @11:35AM (#13839831)
Do you know if with Travelling Ruby is possible to create a windows executable with a GUI? I have been using the gem ocra + ruby tk for this.
Re:Porting Ruby to Crystal by diminish on Friday March 10, 2017 @01:04PM (#13840623)
From Ruby to ES6 or Elixir or Crystal or Golang or even maybe Rust? We need comparison of the target languages among themselves.

For example Crystal vs. Elixir.

Does Crystal have A framework like Phoenix or Rails?

Re:Porting Ruby to Crystal by RX14 on Friday March 10, 2017 @01:22PM (#13840753)
Currently crystal doesn't have a large "standard" framework like Elixir or Ruby. There's Kemal, which is what most people use to create web applications in Crystal, however its quite small in scope compared to the previous two mentioned frameworks.

I'm sure large, opinionated frameworks will appear for Crystal but in the meanwhile Crystal and its community are just finding their feet and experimenting with what feels natural in Crystal and what doesn't. Once that's done, I'm sure that knowledge can be crystallized (heh) into a framework like Rails.

Re:Porting Ruby to Crystal by andrew_wc_brown on Friday March 10, 2017 @08:54AM (#13838547)
Won't have to learn GoLang or Elxir. Crystal on Rails!
Re:Porting Ruby to Crystal by ch4s3 on Friday March 10, 2017 @09:44AM (#13838895)
I can't speak for GoLang, but Elixir isn't exactly a straight replacement for Ruby the way Crystal(more or less) is, it makes a lot different promises, and makes different assumptions. It looks familiar, but is paradigmatically quite different. If you are interested in FP, Elixir is a great way to get started.

Crystal seems quite nice though.

Re:Porting Ruby to Crystal by holydude on Friday March 10, 2017 @09:46AM (#13838916)
Crystal also is not Ruby 2.0. It just feels like Ruby the same way RubyMotion feels just like Ruby. But it is not Ruby per se. Nonetheless Crystal really looks cool!
Re:Porting Ruby to Crystal by ch4s3 on Friday March 10, 2017 @11:26AM (#13839751)
Interesting, I've really only written like 10 lines of Crystal, so I guess I should take a closer look.
Re:Porting Ruby to Crystal by amorphid on Sunday March 12, 2017 @08:38PM (#13854297)
Elixir feels nothing like Ruby to me, except for some superficial similarities in the syntax.
Re:Porting Ruby to Crystal by kkirsche on Friday March 10, 2017 @08:44AM (#13838485)
Thanks! I'm so excited for Crystal to hit 1.0 and be production ready. May need to try it out now though. Thanks again
Re:Porting Ruby to Crystal by petre on Friday March 10, 2017 @02:12PM (#13841147)
Does Crystal produce static binaries like Go does or do I have to mess with dynamic library hell?
Re:Porting Ruby to Crystal by Svenskunganka on Friday March 10, 2017 @06:02PM (#13842908)
It produces static binaries like Go does yes.
Re:Porting Ruby to Crystal by grosser on Friday March 10, 2017 @08:06PM (#13843506)
https://github.com/grosser/rubinjam is a super simple way to convert most Ruby gems into a universal binaries. Which is what this whole post was about :)
Re:Porting Ruby to Crystal by dejv on Friday March 10, 2017 @12:17PM (#13840158)
Is there any library for writing UI for desktop apps available?
Re:Porting Ruby to Crystal by RX14 on Friday March 10, 2017 @01:26PM (#13840789)
There's libui bindings in a shard here: https://github.com/Fusion/libui.cr
Re:Porting Ruby to Crystal by tomc1985 on Friday March 10, 2017 @11:40AM (#13839860)
Doesn't homebrew require git?
Re:Porting Ruby to Crystal by nerdponx on Friday March 10, 2017 @01:17PM (#13840718)
It does. But macOS comes with Git so Homebrew works without any dev setup.
Re:Porting Ruby to Crystal by catnaroek on Friday March 10, 2017 @01:05PM (#13840641)
For some reason, I zeroth thought the title meant “Porting MRI to Crystal”, which would have been truly awesome.
Re:Porting Ruby to Crystal by hashkb on Friday March 10, 2017 @10:38AM (#13839360)
> Using rubygems to distribute ruby code is sometimes done but then sometimes it’s frowned upon

Wat? Rails?

Re:Porting Ruby to Crystal by jdminhbg on Friday March 10, 2017 @12:56PM (#13840559)
The author means as a means to distribute programs and executables, not libraries.
Re:Porting Ruby to Crystal by squar1sm on Friday March 10, 2017 @01:15PM (#13840705)
Yeah, that's what I meant. :)
Re:Porting Ruby to Crystal by hashkb on Friday March 10, 2017 @01:21PM (#13840741)
OK... Rails is an executable too. So is Rake... tons of executables are easily installed and managed with Rubygems.
Re:Porting Ruby to Crystal by squar1sm on Friday March 10, 2017 @06:41PM (#13843125)
I think of Rake/Rails as dev tools that are executables. In the post, I mentioned passenger because that was using Rubygems as a distribution mechanism and then they stopped doing that. I don't know if it's a hard / fast rule or even who would enforce that rule ... I was just mentioning that maybe it's an anti-pattern?
Re:Porting Ruby to Crystal by cderwin on Friday March 10, 2017 @01:29PM (#13840822)
Development tools often are, but almost never exclusively using ruby gems and it's certainly not a universal practice. ANd of course non-dev tools can't be distributed this way.