Notes on the Crystal Language
wiki.alopex.li
wiki.alopex.li
The author might be interested in Roc [1] by Richard Feldman et al, which seems to check all the boxes, including scripting with type inference and glue with good FFI to other languages. It is still in early stage, though, since it is a very ambitious project.
I was wrong. I’ve never encountered it again. It was a great language, super productive. I helped some people develop a pet insurance service. So weird. I’d work with crystal again for sure.
To me it feels like it never quite reached maturity, although in a better world it would have gotten more support and conquered all territory that is now ruled by the Gophers.
I guess to make a successful programming language, you either need corporate backing or extend an existing one nowadays, otherwise it's really hard to build a stdlib of modern proportions.
It has been a while so I can’t recall very clearly, and I have a feeling the community and docs around it are all much better now.
it would surprise me if the stdlib was the issue. you can clone the ruby, python, or go standard libraries, and that would get you into a good state pretty fast; those languages have already done the work to assemble a standard library that people seem satisfied with by and large, and translating code into a new language is far easier than coming up with what should go into a library and then designing and implementing it from scratch. still takes time and effort but there's a clear roadmap if you go that route.
I suspect the real weakness is the thousands of third party packages for stuff that is too specialised or niche to be in the stdlib, but when you need it you really need it. (e.g. I have recently felt the need for an implementation of the blossom algorithm for graph matching in elixir; in python or ruby it's already done for me and available as a package)
As the author notes: the typing system is very pleasant. And the standard library is great!
Generics work fine.
The testing story is very good (almost as good as rspec).
Have some experience with the Threads but won’t comment extensively as that’s about to get some big changes in the next minor release or two.
Overall: highly productive for high-performance backend API servers and background task daemons. Way more fast and pleasant to write than Rust or Go (IMHO).
The author complained about the standard library, specifically the Dir module using inconsistent types and the implementation details of Temp files potentially leading to security flaws, leading me to think there are more warts he didn't cover.
Dir module works fine, though maybe the docs could be improved. https://crystal-lang.org/api/1.13.3/Dir.html . The stdlib code is also highly readable: https://github.com/crystal-lang/crystal/blob/d14d04562/src/d... shows that #each_child just calls #read and yields it to the block, so I don't think this is really a wart :)
For our API server https://api.heiioncall.com/ , on my Ryzen 5950X, with a warm CRYSTAL_CACHE_DIR ("where Crystal caches partial compilation results for faster subsequent builds"), making a one-line change:
Without --release:
6.11user 2.37system 0:08.19elapsed 103%CPU (0avgtext+0avgdata 590844maxresident)k
With --release: 76.54user 5.49system 1:25.16elapsed 96%CPU (0avgtext+0avgdata 696876maxresident)k
So let's call it about 9 seconds while developing, or 90 seconds for a CI build with full release optimizations.Sure can.
$ cat break.cr
(1..).each do |x|
break if x > 2
puts x
end
$ crystal break.cr
1
2
$
The answer to Crystal questions that end in "like you can in Ruby" is usually "yes." The language really is just Ruby with static typing, warts and all. Most random snippets of Ruby will run just fine when compiled as Crystal.Crystal also documents that it will fail if the block contains return or break statements[1].
[1]: https://crystal-lang.org/reference/1.13/syntax_and_semantics...
Without that, it just looks like the author has an insatiable love affair with rust and their arguments lose credibility. Of course if they’re trying to smash Rust semantics into any other language they’re going to be disappointed.
We've been wondering about why it's worth the money for these sponsors. The links ideally shouldn't have much effect because they're marked as `sponsored`. Anybody got any ideas?
Either way, it's money that helps the project so we're fine with accepting it.
Is it an artifact of the Individual/Organisation split of OpenCollective? I see the top 10 individuals that have put in $1000 or more.
All sponsorship contributions pay some development hours, so they're valuable to improve the project.
Sponsors presentation is only based on their _current_ contribution, not the accumulated total.
I get that money is hard to come by, but I hope you realize that you might be doing more than $1500/mo in damage to the project by accepting these ad placements.
Quite frankly, this is something new to us (ads paying enough to be there), so we're still figuring out.
> Fake reviews not only waste people’s time and money, but also pollute the marketplace and divert business away from honest competitors.
Labeled as an ad or not, you may well lose sponsors over this who don't want to be associated with that kind of behavior, and you're certainly losing potential users and contributors here on HN. My perspective on Crystal has changed from positive (I always love new programming languages) to negative over the course of this conversation, and I'm sure I'm not the only one.
This damage can't be measured as easily as money flowing in can, but it's very real and you shouldn't discount it. Some of us don't believe that receiving money for something is sufficient justification to do it.
https://www.ftc.gov/news-events/news/press-releases/2024/08/...
Not sure what you're supposed to do as the project maintainer, might also be a bit strange to selectively only display some sponsors that you think are "trustworthy"?
That they're starving open source developers doesn't remove the obligation to vet their sponsors before posting their links.
The comment at the end
OO language with a static type system that feels as low-friction as a dynamic one
Sounds nice, but does the performance act like a dynamic language or is it super speedy? I'd be happy with half the speed of C.
I'm still on the lookout for a language that feels as low-friction as a dynamic language but could do some form of iterable.map in parallel on all cores transparently.
There's a blog post on paralellism in Crystal https://crystal-lang.org/2019/09/06/parallelism-in-crystal/ but that's a fair few years ago now.
Pause times can exceed 2000ms. No doubt some code changes could help but the fact remains the GC is not an optimised one.
There are works in libgc to allow incremental collection, but it is not yet ready for the needs of crystal (or at least it wasn't the last time I investigated).
Also, is it possible to use RC with crystal?
My Crystal implementation of idle-time garbage collection is here: https://github.com/compumike/idle-gc though please note that its idle detection mechanism only works for single-threaded Crystal programs.
An analogy is to imagine a single employee (thread) operating a convenience store. If there are customers waiting in the checkout line (latency-sensitive requests), the employee should priorities serving the customers ASAP! But once the line is empty (thread is idle), that might be a good time to start sweeping.
Right now, with automatic garbage collection, the employee only decides to start sweeping the entire store while in the middle of serving a customer! (Because that's when mallocs are happening, which may trigger automatic GC.) Pretty ridiculous!
With idle-time GC, the sweeping happens entirely or mostly while there are no customers waiting. This may not show latency improvements in an artificial benchmark where the system is running flat-out with a full request queue, but in the real world, it changes GC from something that happens 100% of the time in the middle of a request is being served (because that's when mallocs happen and trigger automatic GC), to something that only rarely or never happens while a request is being served.
Even better would be to combine idle-time GC with incremental GC, so that the employee could put down the broom when a new customer arrives without finishing sweeping the entire store. :)
See also "Idle Time Garbage Collection Scheduling" in Google Chrome (2016): PDF at https://static.googleusercontent.com/media/research.google.c...
If you can get past the typical "ew parenthesis instead of curly-brackets" and prefix/Polish notation, Clojure is great for this. You'd normally do `(map a-func my-elements)` but if you want the map processing to be parallel, you'd change `map` to `pmap` without any other changes needed.
I know almost nothing about Crystal, so I can't make a fair comparison between them. Julia is used in scientific computing, where parallel clustered processing is essential.
I don't like subthreads which hijack a Language A post to talk about Language B, so I'll resist making an elaborate pitch, but Julia does fit the bill for what you're on the lookout for.
Good catch. The API should be opening the tempfile atomically (the best option), or at least should use a CSPRNG for its random suffix. It doesn’t, currently.
I think the worst thing an attacker could do here if they could somehow predict the generated names before the file is created is DoS the mktmp call by racing ahead of it 100 times until it gives up.
[1] https://github.com/crystal-lang/crystal/blob/release/1.13/sr...
It would be a totally different thing if it could run Rails, which is one of the things I do in my job. The speedup would probably justify using it, especially when running tests on my laptop. My customers are perfectly happy with the performance of Rails on their servers. Same with the ones using Python with Django.
At https://heiioncall.com/ we combine the two and use Rails for the human-facing parts, and Crystal for the machine-facing parts (inbound API server calls, and outbound HTTP probes). For us, the number of machine-facing requests per second is so many orders of magnitude higher than human-facing requests that Crystal's performance and lower footprint is valuable there. While on the other hand, the conveniences of Ruby on Rails are still great for a conventional human-facing web and mobile application.
The audacity of Rustaceans is so thick.