Abstract: Crystal is a general-purpose, object-oriented programming language. With syntax inspired by Ruby, it’s a compiled language with static type-checking. Types are resolved by an advanced type inference algorithm.
No wonder it wasn’t on my radar. I’ve never really dug into Ruby, so I hadn’t seen anything on Crystal prior to the discussion here. It appears that a lot of features are crammed into some of the statements and keywords because the code example is so much shorter than the comparison code.
Ruby became somewhat well known from Ruby on rails.
“Ruby was intentionally designed to be a beautiful, elegant, and human-centric language. Its creator, Yukihiro “Matz” Matsumoto, famously prioritized developer happiness and productivity over machine optimization, striving to create a language that felt natural and joyful to read and write”
Crystal code can be surprisingly compact. But once you get used to using those features, you really miss them when you are trying to figure out how to do the same job in another language.
Yeah, that explains for me; I didn’t do anything with Ruby on Rails, but Crystal does sound interesting to me; I’ll see if that translates into testing it out. It does. I tried going to the Crystal site and I typed in the gigasecond program. I don’t think I had any errors in typing; I carefully typed in each line, but one of them delivered an error in the compile test server on the app page; it was 1.000000000 so unless I counted wrong or that’s too many digits for the test program, something was off.
I did also download the image and put it on MX Linux for now; I set it up, but I haven’t done any more; it’ll be there when I can spare more time.
I never got into the Ruby on rails thing either, but at some point I was looking at different languages to compare performance with perl, and so I looked into Ruby, Python, Julia, command-line php, and others. Ruby was fun to program with.
I’m running MX 25, but the Crystal in the Debian repos is pretty old, so I got the latest package direct from the crystal site.
That gigasecond program works for me when I add some test code:
[jjs@bella crystal-test]$ cat gigasecond.cr
module Gigasecond
def self.from(start : Time) : Time
start + Time::Span.new(seconds: 1000000000)
end
end
p “1 gigasecond after 2011-04-25:”
p Gigasecond.from(Time.utc(2011, 4, 25))
[jjs@bella crystal-test]$ crystal gigasecond.cr
“1 gigasecond after 2011-04-25:”
2043-01-01 01:46:40Z
[jjs@bella crystal-test]$