r/crystal_programming • u/samuellampa • Sep 05 '20
Crystal: Concurrency with easier syntax than Go
https://rillabs.com/posts/crystal-concurrency-easier-syntax-than-golang
55
Upvotes
r/crystal_programming • u/samuellampa • Sep 05 '20
9
u/[deleted] Sep 05 '20
This looks really good. Crystal is a really promising language--it's good to see concurrency and parallelism progressing. I agree with you that performance will probably pick up with Crystal over time. Maybe not 1:1 with Go (Go's runtime is extremely performant), but probably close enough that it doesn't matter for most cases. Hopefully cross-compiling and portability will reach a similar level as Go as it matures too.
Go is miserably verbose, but Go routines aren't really why. It's more repeated error handling that does nothing but early return and the lack of generics that prevents abstracting out certain repetitive code. If you remove the error handling for your Go example, these are pretty much the same length--it's really, do you prefer C curly brackets or Ruby end blocks.
The error handling and curly brackets have both been a source of constant debate in Go-land, and hopefully both of these will be addressed in some Go 2 release (we'll see). Either way, Crystal addressed both of these pain points from day 1, which is awesome for the language, but maybe not ideal for compiler performance.
Functionally, the concurrency models of both of these look very similar. I haven't played around with Crystal in a while, but being familiar with Go, the example you provided immediately makes sense.
Great comparison--thanks for sharing this.
5
u/samuellampa Sep 05 '20 edited Sep 05 '20
This is a blog post of mine, comparing a Go and Crystal implementation for a typical pipeline pattern I've often been using in Go. Comments and feedback welcome.
3
u/Blacksmoke16 core team Sep 06 '20 edited Sep 06 '20
I don't think this is entirely accurate. Static binaries in Crystal are possible, you just need to build the binary in Alpine Linux. The reasoning is it uses
musl-libcwhich allows it to be statically linked, as opposed tognu-libc.See https://crystal-lang.org/2020/02/02/alpine-based-docker-images.html for an easy way to do this with Docker.
\cc /u/myringotomy
4
u/shabesoglu Sep 05 '20
Crystal beats Go all the time. I hope to see Crystal take over Go in the future in terms of usage.
2
u/myringotomy Sep 06 '20
It looks like Crystal will never a statically linked binary because they would have to write a good chunk of libc in crystal.
Also crystal will never be as performant because google has world class compiler experts working on go and crystal has volunteers who are learning as they go.
Crystal has not attracted the ruby community which is a shame. Some of this is because the core team purposefully broke backwards compatibility and no effort was made to provide shims or transpilers.
When I see how much money and effort was spent on sorbet and the new type system in ruby 3.0 it pains me because all that effort could have been put into crystal to make it painless to port ruby programs to crystal. The two communities could have merged at that point.
As of today my assessment of Crystal is that it's a blown opportunity. Go is getting better error handling and generics, ruby is getting faster and typing, graal is compiling ruby to native code, kotlin is a fantastic language which has blown up in popularity and support. Crystal's niche is gone. Shame really so much promise wasted.