Hacker News new | past | comments | ask | show | jobs | submit login
Crystal 1.11.0 Is Released (crystal-lang.org)
117 points by ksec on Jan 14, 2024 | hide | past | favorite | 78 comments



It's been a while since I heard about Crystal.

What's the state of Windows support.

How did the compiler speed drama unfold?


> What's the state of Windows support.

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

> UPDATE 2023-04-24:

> All the main platform features for Windows are finished!

> There are still some smaller stories pending. Project board: https://github.com/orgs/crystal-lang/projects/11/views/5

> You can support the ongoing development financially: Windows suppport (https://opencollective.com/crystal-lang/projects/windows-sup...) project on Open Collective.


Is it just me, or does Crystal have a disproportionate amount of Windows demand? I feel like every time Crystal comes up, someone asks (or complains) about Windows support.


Crystal Core developer speaking.

I don't think it's disproportionate. Windows is a huge platform with lots of developers. Also you don't hear anyone asking for other OS support because all other major operating systems are supported. So there's no real comparison.


Anecdotal, but I think this is just the case with all projects of this nature. People on Windows don't like not being able to use stuff.

The same thing was happening with Bun, and yet I've met lots of Windows developers who hate JavaScript.


Windows isn't popular on HN, but it's a major platform with a lot of devs. You gotta get out of the HN bubble.


It took me 2 decades to get out of the Windows bubble.

I'll enjoy my time here when I can get it.


Crystal is a nice language to write utilities with. Usually with utilities you want to distribute it to other people, many of them can't just install the whole toolchain to run the code. So naturally we want a fully portable windows exe file that can be run independently.


I sponsored a bunch of work on this years back; I wanted it so I didn't have to use Go for cross-platform binaries for a CLI client. I ended up having to use Go, but I hope one day it ships so I can avoid it a little more (I don't hate it, but prefer crystal).


I've noticed a lot more developers on Windows across the board, as more folks learn programming.


I asked because Crystal was notorious for not having it.


If a language doesn't have Windows support then it's inappropriate for commercial native application development.


It looks like Crystal is gaining traction.

Which companies use Crystal in anger / production in front of real users?


I believe Kagi is a heavy user of the language.


~70k LOC Crystal

Mentioned in the crystal conf talk held by a Kagi Developer

https://youtube.com/r7t9xPajjTM



My last company (Rainforest QA) used it in quite a few places when ruby wasn't fast enough, though a lot of Go too.


At Heii On-Call, we use Crystal to power the API server https://api.heiioncall.com/ as well as other internal components.


do you use kemal?


Hopefully they use Grip, a much better framework with encapsulation


Invidious, a self-hosted YouTube front-end. is written in Crystal.


And its resource usage is depressing. Isn’t Crystal garbage collected? I’m not sure why it has memory leaks.

Also, >300 MB of RAM usage (in docker. Some might be the system) with only 2 users after running for a while seems a bit too much


Oh is this why Invidious' setup documentation recommends restarting Invidious every hour or so?


I ended up just throwing it 4 gigs of memory and it has pretty much been fine ever since. I do restart every few weeks when it reaches 1 GB though


How would you know the memory leak was the Crystal part?


https://github.com/iv-org/invidious/issues/1438

I’m not the first one facing these issues.


(Not an Invidious user myself. I just looked at the source code a while back to see what they were doing. But I never tried compiling or using it.)



We use it to do nightly sitemap generation of over 30 million links. Takes about 30 minutes, replaced a Ruby (Rails) process that took hours.


As language nerd it is interesting to see the Crystal improvements, congratulations on keeping it going.


Is parallelism used very much in the wild? They mention it's experimental and there's a blog post from 2019, but I'd like to know how mature it is.

https://crystal-lang.org/reference/1.11/guides/concurrency.h...

https://crystal-lang.org/2019/09/06/parallelism-in-crystal/


I have been running https://mailflowmonitoring.com for the past 6 years on Amber (A Crystal framework) it flawlessly manages the sending and tracking of round trip emails for tens of thousands of pings a day.


I like the first code example on https://crystal-lang.org

    # A very basic HTTP server
    require "http/server"

    server = HTTP::Server.new do |context|
        context.response.content_type = "text/plain"
        context.response.print "Hello world, got #{context.request.path}!"
    end

    puts "Listening on http://127.0.0.1:8080"
    server.listen(8080)
Nicely concise!

This would be the Python equivalent:

    # A very basic HTTP server
    from http.server import BaseHTTPRequestHandler, HTTPServer

    class RequestHandler(BaseHTTPRequestHandler):
       def do_GET(self):
           self.send_response(200)
           self.send_header('Content-type', 'text/plain')
           self.end_headers()
           self.wfile.write(bytes(f"Hello world, got {self.path}!", 'utf8'))

    httpd = HTTPServer(('', 8080), RequestHandler)
    print("Listening on http://127.0.0.1:8080")
    httpd.serve_forever()
Would like to see it in more languages.


Haskell with WAI (more or less, guess there is some conversion from `Bytestring` needed when using `rawPathInfo`)

    {-# LANGUAGE OverloadedStrings #-}

    import Network.HTTP.Types
    import Network.Wai
    import Network.Wai.Handler.Warp (run)

    app :: Application
    app request respond = do
        respond $
            responseLBS
                status200
                [("Content-Type", "text/plain")]
                ("Hello world, got" <> rawPathInfo request <> "!")

    main :: IO ()
    main = do
        putStrLn "Listening on http://127.0.0.1:8080"
        run 8080 app


Not exactly the same but various basic HTTP server implementations are presented at https://rosettacode.org/wiki/Hello_world/Web_server


Would not Ruby be the comparison to do? In which case it I think is nearly identical to the Crystal.


TCL:

    proc webServer {chan addr port} {
        while {[gets $chan] ne ""} {}
            puts $chan "HTTP/1.1 200 OK\n Connection: close\nContent-Type: text/plain\n"
            puts $chan "Hello World!"
            close $chan
    }

    socket -server webServer 8080
    vwait forever


That lacks a few things:

    1: The comment

    2: Printing the status message ("Listening on ...")

    3: Outputting "Hello world, got {request.path}!"
       Aka http request parsing and string extrapolation.


From the landing page (and trying a few tutorials):

https://crystal-lang.org/reference/1.11/index.html

I couldn't quite determine the reason of being of the Crystal language. Could someone with experience with the language explain what is its appeal, and why it would be worth trying/learning?

Thanks!


Reason; no idea - but the appeal for me is it's very ruby-like, and super fast (except, compiling). Some programs I've moved from ruby use >10x less memory, and are generally faster. It's mostly as a nice to write as ruby, except the compile time. Concurrency is very go-like, and there are a reasonable amount (not ruby-like though) level of libraries for use.


I'm not familiar with Ruby, and the link to Ruby had completely escaped me. (What's in a name, huh?)

Thank you!


It generates efficient code (similar to a C program, e.g. you could write a reasonable ray tracer), and is concise. Many Ruby programs would not see a size expansion from being written in Crystal. It's also good at interoperating with C programs; it's employs LLVM in a fairly orthodox manner (so, for example, if you run `perf` under Linux, you will get good symbolic output)

I think the Achilles heel for Crystal is its compilation time on small programs with large dependencies. Note the time to build the entire compiler and standard library is not extraordinary for a large program. It's more like, a small program adding its first few dependencies will find itself pulling in a lot of the standard library to compile, and then will level off in its compilation time.

To illustrate why this may be the case, consider the Crystal feature allowing redefining parts of classes, including ones in the standard library. This is both very useful, and if you think about how it affects features like incremental compilation, immensely complicating.

Here's some practical crystal programs.

This Postgres wire protocol driver is comparable to libpq in performance, and supports a lot of features in the protocol, too: https://github.com/will/crystal-pg/

The Crunchy Bridge CLI: https://github.com/CrunchyData/bridge-cli


To me, it kind of sits between Golang and Rust in terms of intent. I think the goal is to deliver reliable runtime characteristics at the speed of a compiled language, while generally only demanding as much specificity as higher-level interpreted languages (i.e. Ruby). For me I reach for it when I want something that's fast (like go or Rust) but which I can write quickly (like Python or Ruby).


My understanding, it's ruby like, but statically typed and compiled. Basically instead of trying to retrofit ruby with these features without breaking things (like Shopify and friends do with JITs, AOTs, sherbert, etc), this is bottom up approach around these features.

Due to it's infancy the packages are sparse, so what some people do is a hybrid approach, where they write their thing in Ruby/Rails and kick out the slower parts to Crystal. This kinda gives the best of both worlds. Crystal (last I checked) had slow compile times, so gives you the dev velocity and package availability of ruby, plus the speed of a compile language when you need it. The compile times on Crystal stay low because you're only writing a small parts/microservices of your application in Crystal.


> where they write their thing in Ruby/Rails and kick out the slower parts to Crystal

What's the story on Crystal/Ruby interop these days? I work on a Rails app that does document automation, and I could definitely find some specific < 1000 LOC segments that would benefit hugely from being 1:1 rewritten into Crystal and integrated with the rest of the app.


AFAIK, it's the same as any other language w/ Ruby.

Http micro service, IPC, or FFI.

There were some attempts to do inline crystal, like what Mojo does in Python, but I don't know if any of them became stable long term solutions.

There's probably a way to get native C ext speed, you can see an old attempt here:

https://www.akitaonrails.com/2016/07/06/trying-to-match-c-ba...

But at any rate, it'll be better than ruby.


Why would a language need a specific reason to exist? It's a nice language with Ruby-ish syntax, strict typing, a go-like runtime and it compiles down to something quite fast if you take a little bit of care.


I interpret the question less as asking for justification for why it exists and more as wanting to learn what problems it ought to be used to solve because of an interest in putting it in one's "toolbox" as it were.


That was exactly how I meant the question, yes. :-)


For me that's the sweet spot for:

- compiled so easy to deploy

- easy to write compared to Rust, when you don't care about being super reliable

- still keeps things typed and better than in Ruby

- lower memory usage than Ruby/Python (and usually an easy 10x jump in performance)

I'm relying on it a lot with simple lambda automation. If I wanted to write an efficient server, I'd probably use rust though.


As far as I understand, work on Crystal started when Ruby on Rails was the hottest web framework. The original purpose was going to be running your RoR apps that outgrew MRI. Yes, code would have to be adapted to run on Crystal, but that would be much easier than rewriting everything in a completely new language.


Crystal is basically taking Ruby and adding compilation and a strong static type system.

I enjoy writing it but don’t think there’s any particular reason to try/learn it, unless you happen to also be a ruby dev who prefers compiled, strongly typed languages.


as long as Visual Studio is required with Windows, no thank you:

https://crystal-lang.org/install/on_windows


It only requires vs build tools which is likely for the linker. Other languages like rust does the same.



If you’re already running windows, why do you need the linker to be GNU?


because the GNU linker is like a 100 MB download, and Visual Studio is like 10 GB


And that's an issue because ...?


would you rather pay $1 for a soda drink, or $100?


Where do you pay $1 for 10 GB, let alone $100?


whoosh


The best tooling for each OS is the one from the OS vendor themselves.


Depends on your definition of "best". Visual Studio has lots of great features, but it is sluggish and bloated. I cringe everytime I need to use it.

Also, the MSVC compiler itself often produces much worse code than clang or gcc. I am regularly astonished by its stupidity.


Except GCC and clang need a UNIX like help to even target Windows, let alone everything else expected from Windows applications across the board.



So I install Msys2 instead of Visual Studio. What's the big deal?

> let alone everything else expected from Windows applications across the board.

For example?


Drivers, UWP/WinRT as two examples.


Fair enough. But for typical C++ GUI desktop apps I will always prefer Qt + Msys2 over anything Microsoft has to offer.


[citation needed]


That was my citation, you're welcomed.


I see you dont know what citations are


As per Oxford Learner's Dictionaries,

- words or lines taken from a book or a speech

- an official statement about something special that somebody has done, especially about acts of courage in a war

- an act of citing or being cited

- an order to appear in court

https://www.oxfordlearnersdictionaries.com/definition/englis...

Consider I am citing myself.


folks, lets go ahead and quote this user again:

> The best tooling for each OS is the one from the OS vendor themselves.

and here is their defense of that position:

> As per Oxford Learner's Dictionaries

because yes, the dictionary is the correct place to find information about operating systems. LOL


Common sense


I see you have never used Visual Studio


Used VS since 2001. Then started developing on Linux and Mac, which I prefer. But here you don't need the full VS installation, only the build tools and Windows 10 SDK, and apparently it can be installed by a script. It's a non issue. Otherwise use WSL then you won't need VS https://crystal-lang.org/install/on_wsl/


the fact that you're even suggesting WSL shows how out of touch you are with current Windows development.


It's an option on Windows that avoids Visual Studio. If you don't like it then don't use it.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: