Hacker News new | past | comments | ask | show | jobs | submit login
Crystal 1.1.0 (crystal-lang.org)
247 points by bornelsewhere 9 days ago | hide | past | favorite | 65 comments





Finding a description of what the language is actually about on the home page was hard, so here it is: https://crystal-lang.org/api/1.1.0/

The old slogan used to be "Slick as Ruby, Fast as C" but I'm guessing that just invites people to constantly compare runtimes to C and be like "look! it's 50% slower when blahblahblah" when comparing 10ns to 15ns.

That said, I do think they should put the "why" in clear text. Ruby made no apologies for being a language "for the programer" while Crystal is meant to be a language "nice for the programmer with slick syntax and a modern type system AND compiles to very efficient bytecode that's comparable with C (at the cost of more time spent compiling to reach those goals)"


There's a list of what they consider important highlights, with snippets, if you scroll down https://crystal-lang.org/

* Syntax: Crystal’s syntax is heavily inspired by Ruby’s...

* Type System: Crystal is statically type checked...

and so on


I'd love to see a "why" somewhere in there... telling me that its syntax is similar to Ruby and that it has a type system (which Ruby also has as of version 3, yeah?) isn't particularly helpful in telling my why the language is compelling.

I don't really see a "why use Crystal instead of Ruby" (or any other language, really) explanation anywhere. Maybe the things listed on the main page are meant to be that? Even if it's not on the main page a comparison would be nice in the docs (https://crystal-lang.org/docs/) or the reference (https://crystal-lang.org/reference/)


The "Why?" is literally right there, in a big bold heading, directly under the goals: https://crystal-lang.org/api/1.1.0/

Crystal is a programming language with the following goals:

Have a syntax similar to Ruby (but compatibility with it is not a goal) Statically type-checked but without having to specify the type of variables or method arguments. Be able to call C code by writing bindings to it in Crystal. Have compile-time evaluation and generation of code, to avoid boilerplate code. Compile to efficient native code.

Why? We love Ruby's efficiency for writing code. We love C's efficiency for running code. We want the best of both worlds. We want the compiler to understand what we mean without having to specify types everywhere. We want full OOP. Oh, and we don't want to write C code to make the code run faster.


Crystal started way before Ruby's static type system[0].

Matz even mentioned Crystal as a study case while explaining what Ruby's static type system would be like - back in 2016[1].

[0] https://manas.tech/blog/2016/04/01/the-story-behind-crystal/ [1] https://youtu.be/1l3U1X3z0CE?t=1755


Ruby's type system is completely optional using separate definition files (except Sorbet, which isn't part of the core language), while Crystal's is built in and required.

It also seems like Crystal is compiled, yeah? Would it be safe to say "Crystal is like Ruby but compiled and faster"?

You can also think of it as "what if golang had a real type system and ruby style syntax".

Crystal is like Ruby but not dynamic, with macros, without reflection, with arbitrary API changes to the core types that are shared, with value/reference type dichotomy, compiled, and faster.

Or, with apologies to the late Douglas Addams, Crystal is almost, but not quite, entirely unlike Ruby.


Crystal has compile-time macros/reflection, instead of runtime.

The language itself is very interesting. I've dabbled a few times and really like the clean ruby-esque syntax.

What puts me off delving further is the lack of support in various editors / IDEs / Treesitter etc. I think the core development team should really devote some resources to this, as I'm sure I'm not the only one deterred by this dearth of tooling.


Lack of support for native Windows[1] is probably not helping adoption as well.

[1] https://github.com/crystal-lang/crystal/issues/5430


I’ve been playing with Crystal a lot (every night) for the last few months.

It’s really fun language, and I don’t have even have any Ruby background!

The main pain points from where I’m sitting are things like debugging and incremental compiling. You can throw lack of tooling in there too I suppose.

The dev team knows and is working on these, but they are a small community based team so don’t expect they same resources as in Go or Swift.

FWIW I’ve been having good experiences with Sublime.


As per my original post, while the lack of tooling is my biggest pain point around the language ecosystem, inside the language itself, my main gripe is with the error messages. I find them quite impenetrable a lot of the time. Which is not ideal when confronting a new language.

Crystal could take a leaf out of V or Rust's book here. Whatever you think of the languages themselves, the error messages are top notch. Errors that say "Ah. I see what you were trying to do here. Maybe you should try this instead?" are so much more helpful than "Why on earth did you do that?!"


I am also having a better experience with sublime than with vs code.

There's a few LSP implementation that are very usable: https://github.com/crystal-lang-tools/scry, https://github.com/elbywan/crystalline

Beginning of a tree-sitter parser here too: https://github.com/keidax/tree-sitter-crystal


Honestly, until they provide some more support at least in the editors and IDEs field and support native Windows Crystal is not going to be more than a fun tool. I like it, because the general developer experience I had was really pleasant, but I cannot really use it for work.

My personal experience has been pleasant, and i think it is a bit faster than go. Also the easy syntax and better object Oriented features is a plus.

Which IDE/editor do you use? I've had good experiences with Sublime and VS Code.

I like the language but I haven’t tried it out yet. I’ve heard that the compile times can be very long. Is that improved or are there workarounds?

There will be an interpreter, so at least the feedback loop when developing will be fast enough.

Time to compile an optimized binary will be still slow for the foreseeable future.


That's great news! Is the interpreter being developed already? Anywhere we can follow the progress?

It's kinda working right now, with some missing features like exceptions raising and catching, block closures, c-library binding (only libc works IIRC).

You can follow the activity here: https://github.com/crystal-lang/crystal/pull/10910

I was pleasantly surprised myself that the interpreter actually already somewhat worked, as you can see in the demo: https://www.youtube.com/watch?v=een_W1YEICw&list=PLe1-A91ZPT...

The creator also claimed that the interpreter only need a few more months to finish.


There are published video from the latest Crystal 1.0 Conference

https://twitter.com/postmodern_mod3/status/14176736892444672...


Look at their improvement (2x) in HTTP/RPS after moving to io_uring. It's not there yet though

https://github.com/crystal-lang/crystal/issues/10740


Oh interesting, Ruby doing something similar as well, although not official.

[1] https://twitter.com/ioquatix/status/1386594287085780992?s=20


How much of that is libevent vs. io_uring and not epoll vs. io_uring? It would also be interesting to compare to other frameworks/languages on the TechEmpower Web Framework benchmarks.

BLUF: I love crystal and can't wait for it to get the attention I think it deserves.

To give a bit of history of myself and programming languages, I first started as an EE/CS major working with ASM/C/C++/Matlab for EE and C++/Java/Lisp for CS. Up until graduation, it was just a given that programming languages were just a concession given to you so you didn't have to write assembly. OO in the form of C++/Java was the "better alternative" to imperative C. Lucky me.

Then I heard about Ruby and Ruby on Rails. After reading "The Ruby Programming Language" and working through the examples, I was blown away by the idea that a language could be for a programmer and be a way to express ideas rather than something we translate ideas into. Metaprogramming and mixins and Procs oh my.

Then I started working through Project Euler questions with Ruby and it all came crashing down with the reality of Ruby's runtime. Ruby gave me expressiveness but just could't give me the speed of my equivalent C/Java code. Granted, I was definitely doing very sub-optimal algos but even then, C/Java just didn't care and gave the answer in seconds, not minutes.

Since then, Java & JS have paid my bills. I've seen the popularity of Ruby die as Rails fell out of style when Twitter moved away.

I've messed around with Crystal, trying to work through the problems in "The Go Programming Language" in Crystal and finding that Crystal is a beautiful language and fast as hell. That said, there's always a trade-off right? Crystal's trade off is in compile time, especially with --release. However, I think that's a reasonable trade-off since your release builds should be on a beefy server and it could save you $$$ if it means your actual production servers can be lean as hell. That said, I'm also aware that this problem is exactly one that the Go language was meant to address (C++'s exponentially growing compile time).

Crystal definitely needs:

1. IDE/Debugger support, understandable for a new language, but the language should be "finished" and tooling needs critical attention

2. Libraries. The classic problem of any new language.

3. Major sponsorship (would greatly help with point 1 & 2)


It would be great if someone compiled a list of important libraries missing from the ecosystem.

There's one here: https://github.com/crystal-community/crystal-libraries-neede...

Not sure how active it is, though.


So I am currently making an api server in Crystal and I adore this language. I would add some pros/cons for folks who are interested in trying it out;

Pros:

- Elegant syntax. Crystal is highly inspired by Ruby and it has a lovely elegant syntax. Syntax is important to me and the clutter of symbols and the busy syntax is why i struggle with Rust.

- gorgeous type system. F# is the only other language I can think of which has this lovely and complete a type system. The way Crystal handles Nil (its a type) just feels great in practice.

- Perf wise, Crystal is blazing fast. It seems to be marginably faster than most compiled languages like Go, Nim etc in the benchmarks. Though at that level the difference isn't much.

- batteries included stdlib

- decent documentation. It could be better but imo its good enough. I rarely have to look beyond the documentation if I get stuck anywhere.

- small but amazing community. the folks in the community like Ali, blacksmoke, Oleh, Ary and many others etc are super helpful and always ready to teach a newcomer.

Cons:

- Lack of Windows support. The biggest elephant in the room. the good news is that this is under development and even in this release a lot of progress towards a Windows event loop was made. But if you are going to do web dev, you can always go with wsl for the compilation as most of us do.

- Slow compilation speed. Its faster than Rust/C++ but if you are coming from an interpreted language the 5-10 seconds it takes to compile your small project rankles a bit.

- DB drivers need to be better. They currently don't support pipelining, ssl, async etc. Not a big deal as the Crystal drivers are performant enough. but I think if these were there, Crystal would get at least 20-30 ranks in the techempower Fortunes benchmarks.

- IDE tooling is not yet there.

- Small community and hence lack of community packages. Often stuff will have to be done by hand. Things like oauth, openssl conversions etc will need some work from you.

- no http/2 support

- The lack of a BDFL and corporate sponsorship. This means that the language growth is less structured and highly dependent on the community leaders.

Here is an old comment I wrote about Crystal on HN. it is still as true today as it was then;

----------------------------------

I have a love-hate relation with Crystal. Every few months, disenchanted with the core maintainers' priorities, lack of platform and tooling updates and overall deadland syndromes - I denounce Crystal, promise I will never use it again, startup a golang or Rust project, make some non trivial toy stuff and then come crawling back to Crystal. I hate the fact that I love this language and the fact that nothing else (except perhaps f# and nim) seems to have the same effect on me.

My favorites Crystal features are its do-end syntax, dat sexy type system hnnnnghhh... , domain modelling using sum types, null checking using types, ultra simple OOPs, insanely productive std and its sheer performance.

The bits about the language I detest are the overuse of macros, the utter lack of any platform (windows, http/2 etc.) or tooling improvements (IDE support, slow compilation). The core maintainers are amazing but have a weird obsession with just refactoring the language semantics. Things which really would matter for any language usage are just relegated to GH issues which haven't had any comments on it for months (if not years).

The lack of a BDFL and corporate sponsorship really hurts Crystal bad. Its a language without directed growth. For a language which seems to be used the most for web servers, it lacks http/2, db pipelining and async db drivers. There have been plans for redoing the http module for years but it hasn't been done yet.

Yet, I love this language despite all its shortcomings. I find it to be one of the most readable languages out there. The community is full of amazing individuals who are ever helpful and welcoming. The core maintainers are super talented developers who really value quality of code.

Right now I am working on an api servers and have 3 early implementations - one in Rust-actix, one in pure crystal (no framework) and one in Go-Fiber. The joy of using Crystal and feeling like I am in control of the project are reasons which are pushing me towards using Crystal for the project. But I know that by the next few years, we likely still wouldn't have http/2, async drivers, nice IDE support and many other features that I really need.

And so, I will likely have to go with Go. (Rust syntax is just too complex for my taste. And I am not talking about the celebrated borrow checker).

I like go.

Go is simple.

Go is Productive.

Go is... just not Crystal.

-----------------

Epilogue: I did not go with Go. Its error handling and opinionated formatting turned me off so much that I have returned back to crystal. :/


Most of this is still true, but this is the most balanced review of Crystal I've have read so far here.

Although I use Rust most of the time, I keep having a look at Crystal and appreciate its simplicity and can get alot of things done with it rather than fighting with the borrow checker.

Very happy to see it reach 1.0 and further.

> and corporate sponsorship

Well there are companies (and smaller individuals) that are still sponsoring it every month. [0]

[0] https://crystal-lang.org/sponsors/


Compared to the Google sponsorship of Go and the Amazon sponsorship of Rust, a few thousand from unknown vaporware companies isn't really a level comparison.

(disclaimer: I was once a coffee sponsor of Crystal myself)


> a few thousand from unknown vaporware companies isn't really a level comparison

I see, So: "If a company that I don't know about is putting money into a language, it's doesn't really fit my definition of 'real' sponsorship"

It still counts as sponsorship whether if it is a FAANMG company or a tiny startup and there are companies that use Crystal that are sponsoring it monthly. No need to move the goal posts here.

Probably the Golang people did the exact same comparison to Rust when that reached 1.0 in 2015; way before the Rust foundation was formed or any company sponsoring Rust other than Mozilla.

So perhaps Ocaml (The language that Rust was first written in) doesn't count as well since that has a couple of so called 'unknown vaporware companies' and zero FAAMNG companies on the list of 'sponsors' then? [0]

[0] https://ocaml-sf.org


You're right, the name of the company or FAANG-ness doesn't matter. I didn't claim only FAANG sponsorship matters, but it is important and even more important, the amount of $ does.

I also never said it wasn't "real" sponsorship or didn't count. Don't put words in my mouth. I said it isn't a level comparison.

> any company sponsoring Rust other than Mozilla

Mozilla? never heard of them. I only know FAANG apparently /s

Also, Ocaml has supporters such as Bloomberg and Mitsubishi. Not exactly mom-and-pop startups.

Again, I'm not exactly sure what you're arguing. I'm literally a sponsor of Crystal. I put my money where my mouth is.


> but it is important and even more important, the amount of $ does.

Also you:

> Also, Ocaml has supporters such as Bloomberg and Mitsubishi. Not exactly mom-and-pop startups.

Perhaps Jane Street is also another mom-and-pop startup then. /s

So they (Bloomberg, and Mitsubishi) somehow matter because they're "Not exactly mom-and-pop startups" even though you also said, "the amount of money they are giving matters". Given the OCaml sponsorship levels [0], Bloomberg (Silver) donates around $1250 - $2084 a month and Mitsubishi (Bronze) around $416 - $1249. That is still less than the monthly amount that either Nikola Motor or 84 Codes is putting in combined.

Nikola Motor isn't not a startup and still sponsors and uses Crystal. It seems that they have alot of money left over every month to throw at Crystal even before it reached 1.0.

> I said it isn't a level comparison.

Then congratulations to Crystal for getting sponsors (and companies sponsoring it) even before 1.0 then. They'll probably get more even after 1.0 then.

Never saw that in Rust before the foundation was formed (which should have been done earlier) since its actually Google again (not Mozilla) feeding the majority of the sponsorship funds to Mozilla.

> Again, I'm not exactly sure what you're arguing. I'm literally a sponsor of Crystal. I put my money where my mouth is.

Good and so do the companies that still use Crystal to this day even before 1.0. At least individuals can sponsor it as I mentioned previously. Unlike Go, whose fate is ultimately in the hands of Google for any decision they make for the language.

[0] https://ocaml-sf.org/becoming-a-sponsor/


What's stopping you from going with Nim? Honestly curious, I have my own love-hate with that one, so I have some guesses, but I'd find it fun to "fact check" those and compare opinions :)

Mostly a lack of good web frameworks which are performant and have good devex. Jester the main Nim framework doesn't even have a webpage and that doesn't inspires any confidence. Httpbeast may be fast but it feels like just a PoC. It doesn't even have docs.

Prologue is the most promising one IMO, but it is still very new and its performance isn't as good. But I do keep a check on it.

Overall, Nim needs something like Lucky, Athena, Azu Toolkit etc to feel like a serious web dev language.

That said, I have always been thinking of rolling with just the stdlib stuff so I may do that one of these days.


Author of Jester here.

I agree that a nice website would be great to have for Jester (and I do intend to create one), but I think you place far too much importance on Jester having one. Jester/HttpBeast is used in production by big web apps[1], why doesn't this inspire enough confidence and possibly even more than the other web frameworks you've mentioned?

I think there is an inherent bias that all humans have for shiny design, you should definitely keep it in mind when choosing a technology.

1 - https://forum.nim-lang.org/


I understand that it is frustrating to hear somebody telling you that they lack confidence in your tool simply because it «lacks a webpage», maybe after you have spent so much time creating and polishing it!

However, considering the huge amount of languages/webframework pairs (D+Vibe? Nim+Jester? Crystal+Whatever? Go? Rust? etc.) available today, it is understandable that people pick simple criteria like this to decimate their number of choices. The alternative to start playing with each tool for a few days to rank them and pick the best choice is obviously not possible.


For me, it’s also because of IDE tooling. Nim syntax supports so many different call styles that when you press dot for autocomplete you always see so many options to the point it’s not helpful anymore. I’d love to know if there’s a way around that issue.

This is an excellent summary, at least for the pros and cons.

I find your take on the project leadership interesting, because it is a spot-on description of everything I found to be wrong with Elm. That BDFL was/is not so benevolent. Or maybe he’s well-meaning but terribly annoying. And the language has a mich better claim to being dead than Crystal, where I had not noticed any loss of momentum or activity on GitHub.

(You may well be right on those points as well, as you are clearly more knowledgeable about the dynamics)


> Elegant syntax. Crystal is highly inspired by Ruby and it has a lovely elegant syntax.

Agree 100%. I still haven't written any Crystal, but I read through parts of the code-base, out of curiosity, and it is some of the most pleasant compiler code I've ever read.


You might enjoy Zig then, although it's closer to the Go or C spirit and shares a decent number of the Crystal shortcomings you've mentioned.

It's still pre-1.0 but you might find it interesting, but maybe not for what you're working with right now. https://ziglang.org


I absolutely love Zig, but based on what they praise Crystal for, I don't think they'd enjoy it. Polar opposite syntaxes, do-it-yourself type system, batteries-not-included standard library, and manual memory management? Probably not what they're looking for.

i am intrigued by Zig and have been following it for a while. But i plan on seriously trying it out after the following are availabe; self hosted compiler, http server (or at least a standardized interface) in stdlib and a package manager. Otheriwse the language would not be productive for my needs.

> clutter of symbols and the busy syntax is why i struggle with Rust

Funny you mention this because all the clutter and symbols (operators) in Ruby's syntax is why I never liked it.


I noticed at the bottom that they're sponsored by Nikola Motor Corp... surprising!

Yes (and they still are). They wrote a blog post on using Crystal a year ago as well.

[0] https://manas.tech/blog/2020/02/11/nikola-motor-company/


Was Crystal the power behind Trevor Milton's famed "HTML5 supercomputers", then? Crystal looks nice, faster, more beautiful and ergonomic than Go, but I don't see its application for embedded use-cases, which is where I would think Nikola would target any special sauce, if it has any.

I think they used it for UI work. Crystal has super simple binding to C.

Small correction:

ae = 'a'..'e'

ccae = ['<', *r, '>'] # => ['<', 'a', 'b', 'c', 'd', 'e', '>']

I'm guessing *r in the second line should have been *ae (or ae in the first line should have been named r)

Also

"It is new possible" should prpbably have been "It is now possible"


I'm pretty sure HN is not the place to post corrections for an article; have you tried any of the channels on https://crystal-lang.org/community/ instead?

Thanks! I'll get that fixed :)

EDIT: PR submitted. Feel free to create one next time :)

https://github.com/crystal-lang/crystal-website/pull/172/fil...


Well I never: today I learned about break expressions:

    nine = while 1 do break 9 end
    puts nine #=> “nine”
I love Ruby. I am not sure how I feel about this. It looks useful for the odd thing or two, maybe.

Ruby makes me want to become a programmer.

My dislike for Ruby was one of the main reasons I left my last job... but I think that opinion will probably get an angry mob after me here on Hacker News haha. And honestly, it could have just been the way they were writing Ruby there that drove me to leave, but the language has left a sour taste in my mouth.

What do you dislike about ruby and what do you prefer against it?

Does nine really end up containing a string like that? I would have expected it to be the number 9.

The example is syntactically incorrect Crystal. Should be

  nine = while 1; break 9; end
  puts nine
And yes, it prints "9".

What is going on with the upvotes here? The incorrect comment by OP is upvoted, while this correct comment is downvoted.

  irb(main):001:0> nine = while 1 do break 9 end
  => 9

  irb(main):002:0> nine.class
  => Integer

  irb(main):003:0> puts nine
  9
  => nil
puts might be calling .to_s on the variable, which is why you see a string, but the loop does return an integer.

And just to be clear, to_s will return a string, but it will definitely not do the craziness of converting an integer into an English representation of the number!

    9.to_s
    => "9"

Sorry. Yes, you are correct.

I over-edited my comment to fit a narrow screen, breaking the example.




Applications are open for YC Winter 2022

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: