Hacker News new | ask | show | jobs
by nerdponx 1467 days ago
What makes Rust better for these attributes than any other statically typed language with immutable data structures?

It sounds like Ocaml would do just as good of a job here.

5 comments

Ocaml is absolutely playing in similar spaces as rust. I see the tradeoff there as one of runtime performance (Rust) against less syntax / dev effort (Ocaml). If you don't need your code to go fast, Ocaml is probably just fine for you to use. Hell, Jane Street famously does so and has talked in great detail on their podcast and in articles about the many strengths and tradeoffs involved here.
Given how many startups work with python, which is notoriously slow, this is a somewhat ridiculous statement. Ocaml's performance is probably 50ish% of Rust's at worst, which I claim is more than enough for 99% of the problems out there.

Rust's popularity, again I claim, has almost nothing to with its performance. It's more about the much more modern tooling, relatively simplified language (for most parts, though obviously not all) and superior marketing.

It's more like "if you need your code to go extremely fast" though, which is honestly pretty rare in my experience. Ocaml is no slouch and people regularly build great products on much slower languages and that's rarely the limiting factor.
I don't know OCaml, so I cannot compare the two, but, generally speaking, Rust does not require functional programming, or using only immutable data structures, or using cloning, or using copy-on-write semantics (which have to properly handle the reference-type-inside-a-value-type problem), but works through no-copy data ownership transfer, multiple immutable references, or only a single mutable reference to data at a time, all checked across threads at compile-time. Finally, Rust is not garbage-collected, so it can be used in resource-critical environments, such as embedded, metered serverless, Linux kernel drivers, etc. If you're interested, have a look at the "A Firehose of Rust, for busy people who know some C++"[1] video.

[1] https://www.youtube.com/watch?v=FSyfZVuD32Y

Neither does OCaml.

"Unix system programming in OCaml",

https://ocaml.github.io/ocamlunix

Ever heard of MirageOS, and are you aware that DockerDesktop TCP/IP stack uses parts of it?

https://mirage.io/

Ocaml to this day has issues on Windows. Its a phenomenal tool, but adoption is always going to be hampered while the world's dominant desktop OS is a second class citizen for that tool.
Just like most languages that are UNIX first, like Rust.
No, not really. Rust undoubtedly started on *nix, but all Tier 1 platforms are supported equally[1]. To quote from OCaml's main site[2] A gentle reminder that if you do not need Windows binaries, then a more stable option is to use WSL2, ie when on Windows it is better to use OCaml from within a Linux VM.

Ocaml is great, but its Windows support sucks, and that makes adoption hard in a lot of contexts.

[1] https://doc.rust-lang.org/beta/rustc/platform-support.html

[2] https://www.ocaml.org/docs/ocaml-on-windows

Any language that calls themselves systems programming language, on Windows, must have first class support for COM and WinRT, in their various workloads.

Rust support for them is pretty much WIP.

And then there is the whole matter that Windows shops love to ship binary libraries.

There has been a Microsoft supported Rust projection of WinRT for a few years now [1].

[1] https://github.com/microsoft/windows-rs

Now go try to write a UWP app with it, or a COM library to be consumed by .NET in MTA mode.

Why do you think I mentioned WIP?

The competition bare minimum is MFC, ATL, WRL, including Visual Studio tooling.

What languages/platforms do meet this criterion? .NET, C, C++, Python? I know pretty much nothing about Windows system programming, but I wouldn't be surprised if most programming languages really are "Unix first".
.NET languages, C++ and Delphi are the elephant in the room regarding Windows.
Ocaml wouldn't be a bad choice if it were livelier. Few learning resources, and perceived smaller ecosystem create a vicious cycle that hamper its adoption.
What makes Rust better for these attributes than any other statically typed language with immutable data structures?

The ecosystem, even though Rust's ecosystem is still very poor when compared to Java's.