Surprisingly, Crystal seems to be much leaner in runtime size than Rust, with similar performance (although the use case is so simple that even good old Ruby is fast enough).
But then again, I feel you cannot beat Ruby in terms of dev productivity.
Error management through Option values, the borrowing checker... they are cool technologies for a C-like language, but they are not palatable at the beginning (maybe they are an acquired taste like beer?). I am tempted to stretch it a little bit more and see how productive I can become writing Rust code, but also not so sure about the effort.
I think the bit about productivity may certainly be true if you have to use libraries, obviously Ruby has many more available now (maybe forever), but I certainly feel more productive in Crystal now, maybe for things other than the language itself, admittedly. For example, producing a binary makes installation a breeze, and I don't worry about which version I'm running as I point the right compiler at the code; no Bundler now, library installs are sane (at last!); and socially I find the lack of "rockstars" in the main team refreshing, I have no fear of being dissed or dismissed, it makes contributing easier.
As it is from Ruby 3.0 we have built in optional static typing and with interesting projects like Sorbet Compiler[1] we have the option to statically compile making use of that. It's still WIP I believe but it's giving ruby devs some cool options.
1. https://sorbet.org/blog/2021/07/30/open-sourcing-sorbet-comp...
That would be very nice, I agree, though I've always found the FFI interface an under-documented pain so I'd probably end up just using Crystal or using some other way to interoperate, like pipes or HTTP.
On Sorbet, I just hate the look of it. I know it's subjective (possibly that's Ruby's own fault for being so delightful to look at, I'm spoiled!) but I can't abide the syntax. Crystal's is much nicer, and has some extra sugar sprinkled on top for the moments you're most likely to be using it (like external names in method signatures[1] or providing init args) that win out for me.
Sorry about the formatting, I can't work out HN's markdown :/
# Ruby
# from the Sorbet intro
extend T::Sig
sig {params(name: String).returns(Integer)}
def main(name)
puts "Hello, #{name}!"
name.length
end
# Crystal
def main(name : String) : Int
puts "Hello, #{name}!"
name.size
end
puts main "you"
That's so much nicer to my eyes, and you don't need most of it as it will be inferred.Initialisation is nicer, too, (unless Ruby has been updated in this regard too? As I wrote, I use it much less now)
# Crystal
class A
getter name : String
def initialize(*, @name); end
end
a = A.new name: "Hacker News"
puts a.name
or without the getter and keyword arg: # Crystal
class A
getter name
def initialize(@name : String); end
end
a = A.new "Hacker News"
puts a.name
Whatever suits. # Crystal
# Example of external names
def increment(value, by)
# OK, but reads odd
value + by
end
def increment(value : Int, by amount : Int) : Int
# Better
value + amount
end
puts increment 1, 2
but those types are easily inferred so it's actually: # Crystal
def increment(value, by amount)
# Even better
value + amount
end
I could go on because now I'm comfortable with it, it looks much better. I feel the way moving from Perl and C# to Ruby felt.[1] https://crystal-lang.org/reference/1.3/syntax_and_semantics/...
Edit: formatting, of course
a) they would see how far from "better ruby" is Crystal and
b) The Crystal community would be huge.
Are you accusing us both of lying? How strange.
Let's see if your accusations can hold up to Socratic questioning:
- If I haven't open sourced any Crystal projects does that mean I haven't written any?
- I have published several Ruby gems[0], when was the last commit or version bump for any of them? You're more interested that I am, tell me. I really should archive them, thanks for reminding me.
- You missed off my Gitlab, what was the last public contribution I made there? (hint[1])
- What's the last gem I created? I reckon it's this one that I didn't publish[2] because the Rack team changed a public API in such a dumb way that I'd have to rewrite it and then mucked me around with a pull request to Rack that one of the core team copy and pasted in as their own commit while arguing against the pull. Weird, but lovely people, like yourself. Meanwhile, your cookies lack security. Yes, I want to continue working within this language and ecosystem… Does the sarcasm come through in my writing?
- Why did you not check the Crystal repo?[3][4] Github has a search facility. Put my username in, and pick `commits` on the left.
- How did you miss the forks of Docopt.cr[5] and Fancyline[6]? They're right there in my public activity log. Did you not see the merges into Fancyline of my code?[7] I have more to give, just trying to find the time.
- Did you not see forks with commits such as xattr.cr[8], xdg.cr[9], and Pope.cr[10]
- You didn't see I'd provided a project[11] for Mint so it can be run easier with Docker Compose?
- Aside from that I have a whole host of changes to migrate.cr[12] still to push up. You can't know that but you might've guessed that I was at least working with that - and all the other forks of Crystal projects I have.
That is all public and not the half of the Crystal code I look at.
Should I expect an apology? If you were too cowardly to be straightforward with your accusations then I find it stretches credulity far beyond breaking that you could be big enough to provide one. We'll see, like you, I've been very wrong about people in the past.
[0] https://rubygems.org/profiles/yb66
[1] https://gitlab.com/arctic-fox/spectator/-/merge_requests/34
[2] https://gitlab.com/yb66/aes-gcm
[3] https://github.com/crystal-lang/crystal/pull/11201
[4] https://github.com/crystal-lang/crystal/blob/1.1.0/CHANGELOG...
[5] https://github.com/yb66/docopt.cr
[6] https://github.com/yb66/fancyline
[7] https://github.com/Papierkorb/fancyline/pulls?q=is%3Apr+yb66
[8] https://github.com/ettomatic/xattr/pulls
[9] https://github.com/dscottboggs/xdg.cr/pull/1
[10] https://github.com/yb66/pope.cr/commits/master
I don't think you understand how Git works, which probably explains why you missed all the repos I needed to point out to you.
> , and most your contributions are small
What have you ever contributed? Show me.
> The only thing that I wanted to say is that as soon as you start to work in a real project with Crystal you realize that it is not just a better ruby and it comes with it's own set of problems, patterns and etc.
How would you know? Please share the repo in which you found this out. What is a "real" project?
> So I don't see a point to cite Crystal as option to ruby in every thread about ruby.
You've contributed nothing of worth, not even a specific criticism of Crystal, let alone anything worth knowing about Ruby.
> That's my point.
Great point.
LOL, you forked many repositories and didn't push any code. You just proved my point. Just people without experience in Crystal comes to ruby related threads to say "Dude, use Crystal". Happy learning <3
Well, firstly that isn't true, and secondly even if it were true it's a good idea to fork repos you use. So, not only are you:
- childish ("LOL", really? This is HN)
- lying (always the sign of a strong argument)
- unable to search Github effectively
You also show bad development practices. Did you not see what happened this week with Colors.js[1]?
> You just proved my point.
Quite the opposite.
> Just people without experience in Crystal comes to ruby related threads to say "Dude, use Crystal".
Where is your repo showing your experience in Crystal? Or Ruby for that matter. Money where mouth is time, do you even have a single commit to a project in either language?
[1] https://github.com/Marak/colors.js/commit/074a0f8ed0c31c35d1...
There is nothing in the text about Crystal. Why should I talk about Crystal?
> Where is your repo showing your experience in Crystal? Or Ruby for that matter.
I don't have too. That's not about Crystal, but about ruby :)
That's not about me and my code, not either about your little unknown rubygems, but the desire from people like to you to recommend Crystal as "drop-in" replacement for ruby, which is not.. Typical "I'm vegan" comment when people are talking about barbecue.
Happy learning <3
Mendacious to the last. If you find a way to make a substantive or informed observation then do let me know, otherwise, please save it for your friends on Reddit.
now that I read "accusing us both of lying".. how could you interpret it like that? What I can see by your code, you are ruby developer trying to learn Crystal. See you in the next ruby thread ;)
I don't value your opinion in this matter, you're simply trolling now.
> See you in the next ruby thread ;)
I doubt we'll interact again.
Btw, I took a look around your Github and found some really interesting projects (yours and others), thanks for replying!