8 ms·
Ask HN: What's the best “higher level Rust” these days?
After playing with rust, I really like it. However, I generally don't need to write the low level code that justifies the increased complexity of the borrow checker. I would rather just pay the small price for a garbage collector. What language is most like rust, but at a higher level?
To me, these are the things that I like about rust that I'd want to see:
* Getting nullability right, not making the "billion dollar mistake". An integer shouldn't be able to be "null" unless it's part of the type.
* "Algebraic" (Sum and Product) data types. I love Typescript's "integer | null" syntax, but Option<int> or something like that is fine, too. Typed structs/records or tuples.
* Errors as values. Goes naturally with the ADTs, and it feels very robust having the compiler enforce handling all the "Ok(..) | Err(..)" results.
* Focus on the data, defining structs and functions that work with structs. "Traits" as a means of abstraction. Not much in the way of inheritance.
* A nice development experience with a good package manager or other way of finding and using open source code.
* Vibrant and growing community.
* Can develop comfortably on Mac, deploy to Linux. Windows support a "nice to have".
Rust just nails all these things so well, it makes me want to use it even for things that don't seem like a good fit to me, like command line tools or web servers or scripts.
Here are the languages I can think of that might work, but I think they all have some issues:
* Ocaml - Rust's heritage, so it makes sense. But I feel like it's been around forever and hasn't really taken off. And doesn't it still have some sort of concurrency issue?
* Swift - So close to the ideal language, but does it work well outside of the Mac ecosystem?
* F# - Conversely, another great language, but does it work well outside of Windows?
* Java - The last time I used Java in earnest (many, many years ago) it still had the nullability issue, and was too class/inheritance focused for my tastes. I'm not sure if modern Java has improved on this yet.
* Typescript - Is this it? As a language, it actually ticks all the boxes, I think, which surprises me. But as a runtime it's nonexistent, and so you have to compile to Javascript and run on node and all that. I use it and really like it on the frontend. But how is it on the backend for ordinary non-web applications? How's its performance? It feels fiddly to get all the build stuff running, but maybe Deno or Bun is an option here.
* Nim - Kind of off the wall here, but it looks like it might actually be a contender from perusing its docs. But its community is pretty niche, and I don't have a good sense on if its growing or not.
- jonfw 4y agoGolang is continuing to grow to serve this use case. Just like explicitly handling errors though- you'd be expected to explicitly handle null values if you want to be safe from them
- rowanG077 4y agoIn many ways Golang is much lower level then Rust. So I wouldn't say it handles this case.
- jonfw 4y agoI'm not very familiar with rust, would you be able to share an example?
- dfinninger 4y agoI’m not the parent poster, but I would assume they are referring to Go’s typical usage of for-loops over something like Streams/Iterators/Comprehensions. (And other cases where idiomatic Go uses the simpler option)
- losvedir 4y agoI like the idea of Go, except I don't think it quite has the type system that I like. I saw it got generics recently, but that actually wasn't very high on my priorities, compared to being able to say "this value is an integer and definitely not nil", OR, saying "this value is an integer OR it could be nil, and I want the compiler to make sure I'm considering the nil case." And I appreciate that it has the "errors as values" like I was asking about, though, the types don't really force you to handle them, I don't think?
- salmo 4y agoIIRC, you can't have a nil value, just a nil pointer. I like that because it makes you avoid using nil/null/none as a magic value as a habit (not completely, because yeah, pointers). But it's definitely no Rust. It's a very small language by comparison. That's a positive for me, but you can't have all the Rust things and that at the same time. I'm not a "1 language for everything" guy. I tend to choose for the task if given the choice or choose for the team so I'm not stuck being the only one that can maintain it. And for anything more than a toy for myself, I always pick something mainstream. If I'm slapping something together as a 1-off, I tend to go with Python. If I'm writing a CLI, I tend to use Go and I'm using it more for backend stuff. I'll use Java if I have to, because of the team thing. But I won't like it. For toy stuff, I'll pick a language out of a hat just to learn something new. Every few years I'll use a LISP/Scheme.