153 points · by todsacerdoti · 1y ago · 90 comments
I’m also generally very glad at where it went from here. It took a tremendous amount of work from so many people to get there.
Do you think Go fulfills that for you today or do you think there's still space for a new language here?
I can readily see a Haskell inspired System F derivative the compiles down to valid Go, or a more flexible, special cases type theory that encompasses all of Go like Ts->Js. Likely a ‘transpiler’, I hate that term, to Go implemented in Go and you have a self-contained language with more advanced type features and Go’s green thread runtime.
This project proports to be typescript for golang
While Go has the goroutines and they have made concurrent and parallel programming accessible to many, they are a rather raw material that's easy to abuse and use wrongly (leaks, deadlocks, and don't even get me started on writing to a closed channel -- instant panic and program abort).
Rust async is also too raw but in another way: gets wordy / verbose and too implementation-oriented way too quickly -- I never wanted to care about Pin<Box<???>> or what must this or that Future implement in order to be eligible for usage in `select` and whatnot. Those things should have been hidden behind a DSL much like `select` and `async` itself are a DSL / macros / state-machines of sorts. Rust's async just seems... I don't know... unfinished. Zero disrespect is intended (and I do recognize you by your username), I love Rust and I never pass an opportunity to whip up an internal CLI tool with it and my most consulting engagements have resulted in teams highly appreciating such tools, but I can't shake the feeling that Rust's async could be more... polished.
Both Rust's and Go's async mechanics leave me with the impression that somebody thought that they gave the devs enough LEGO building blocks and called it a day. I don't judge. I understand. But as a user of the languages I also have the right to find their async facilities less than ideal.
Erlang / Elixir / Gleam / LFE on the other hand stand on a runtime that has exhaustively analyzed a ton of async scenarios and cover them very well (minus stuff like filesystem operations being centralized through a singleton runtime agent, something you can opt out of, thankfully).
So I'd say both Rust and Go are ripe for either disruption or courageous backwards-incompatible modifications. Their async implementations simply did not go far enough.
And don't get me wrong, I love both and do my best to use them regularly. But it's a sad reality that their "unfinishedness" led to a plethora of footguns that became a badge of honor if you get to know most or all of them, as in: know how to avoid them. Which I don't know why many see as a desired state of affairs. Job security, I suppose.
I would kill for something as terse and explicit as Go but as super strict as Rust but that also has 100% finished async semantics, and has a faster compiler than Rust but optimizing as aggressively as it as well. Yeah, I know: what color do I like my dragon?
All that being said, Rust is the closest we have to a perfect language currently. And that's kind of sad because it has a few things that it really needs to fix if it wants to keep gaining mind-share. I personally find myself reluctant trying to build a career with it. But I'll not digress further.
It seems like over time, a lot of that was replaced with C++-style syntax and semantics. Presumably to make the language appeal more to C++ devs
It looks like Ruby.
The generics look like Java.
Implementation-wise they're the same trick as C++, monomorphization.
Stylistically they're not very like either, however the effect is more like C++ because Rust idiomatically prefers to constrain functions not types so e.g. it's fine to talk about HashMap<f32, f32> a hypothetical hash table of floating point numbers mapped to other floating point numbers - even though we can't use such a type because if we try to insert into it we'll be told that insert requires its key parameter to implement Eq and Hash, which f32 doesn't because of NaN.
In both C++ and Java as I understand it these constraints live on the type not the functions associated with that type, although C++ does not have the same constraint here and is perfectly willing to try to make a hash table of floats... but where a constraint lives on a function in C++ it would behave similarly to Rust due to SFINAE - the function won't match so your diagnostics say there's no such function, probably worse diagnostics than Rust but that's par for the course in C++.
My Ruby claim doesn't hold much weight either if we're talking about the actual implementation.
C++ templates look like an entirely new language within the language.
Rust and Java make generics fit within the aesthetics and ergonomics of the language.
If anything feels "bolted on" to Rust, it's proc macros and (to a lesser degree) async.
I write a lot of chains with block expressions that almost look 1:1 with Ruby.
You could say "The address at T". Curious why people hated it, I might be missing something.
The real reason it was removed in the end was just that it elevated a library concept into syntax. Today's Arc<T>/Rc<T> split isn't really possible in an @T world, for example. Shared ownership is a good concept, but you don't need special syntax to indicate it.
Rust still does this in all sorts of silly ways, such as the ! type. What's the point of wasting an entire symbol that could have plenty of alternate uses on something that's so rarely used and could easily be defined as either a library type (empty enum) or at least be given a custom keyword, such as `never`? (Introduce it over an edition boundary, if you must preserve backwards compatibility.) The fact that it involves some compiler magic is no excuse; that's why Rust uses "langitem" markers within its core library.
I certainly don't disagree that Rust has flaws, for sure. I think this particular one is pretty far down the list, though. I'm not sure what else I'd want to use ! for, and by virtue of it not being used so often means that it's much less of a pain than @T would have been, though I would also argue that 2012 Rust used ~T and @T far more than contemporary Rust does (I still remember pcwalton's mailing list post about how you didn't have to use ~ for comparing strings!) and so was even more painful at the time than would be now.
Compared to what?
Most languages only have one kind of pointer, and they tend to use & and * as operators for them.
I think that tutorial discouraged me from really getting into Rust
Would be interested to hear where this analogy breaks down from someone more experienced than me.
RAII in Rust is like C++, but simpler: there are no constructors, only destructors. The Drop trait gets called like in C++, except that in Rust, moves are the default, and destructors don't get called on moved-from objects, that is, your destructor only runs once.
References are, at runtime, the same as a pointer in C++, except they cannot be null. We also say that they "borrow" what they refer to, which means that the compiler keeps track of the lifetime of the referent. This ensures that the referent always outlives its reference, so that its reference is always valid. This is a compile-time analysis on the control-flow graph of your program.
Does that make sense?
I'm really, really glad I've since picked it back up post-1.0.
continue was called loop for some reason
How strange! Does anyone know why?Terseness doesn't inherently mean less readable.
I do think that that rule is probably not one that would be good permanently.
I agree, with the possible exception of perplexing async stuff.
Rust has very good reasons for not wanting to bless an executor by bringing it into the standard library. But most of those would be moot if pollster was brought in. It wouldn't stifle experimentation and refinement of other approaches because it's so limited in scope and useless to all but the simplest of use cases.
But it does in practice solve what many mislabel as the function coloring problem. Powerful rust libraries tend to be async because that's maximally useful. Many provide an alternate synchronous interface but they all do it differently and it forces selection of an executor even if the library wouldn't otherwise force such a selection. (Although to be clear such libraries do often depend on I/O in a manner that also forces a specific executor selection).
Pollster or similar in standard library would allow external crates to be async with essentially no impact on synchronous users.
- it provides an incentive for libraries to be pollster compatible, rather than requiring tokio. And pollster compatible means executor agnostic.
- libraries would document their library with pollster usage
Sans-IO crates exist but are kind of annoying to schedule correctly on an IO runtime of choice. Maybe lending iterators could help idk
The ecosystem being tokio centric is a little strange though
What do you want Rust to do differently?
What language does async right?
How did Rust not reach its async goals?
Rust even lets you choose the runtime you want. And most big libraries work with several runtimes.
There are several ~~problems~~ subtleties that make usage of Rust async hindered IMHO.
- BoxFuture. It's used almost everywhere. It means there are no chances for heap elision optimization.
- Verbosity. Look at this BoxFuture definition: `BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;`. It's awful. I do understand what's Pin trait, what is Future trait, what's Send, lifetimes and dynamic dispatching. I *have to* know all these not obvious things just to operate with coroutines in my (possibly single threaded!) program =(
- No async drop and async trait in stdlib (fixed not so long ago)
I am *not* a hater of Rust async system. It's a little simpler and less tunable than in C++, but more complex than in Golang. Just I cannot say Rust's async approach is a good enough trade-off while a plethora of the decisions made in the design of the language are closest to the silver bullet.
Lean into being synchronous. Why should I have to manually schedule my context switches as a programmer?
As an example: Call N functions to see which one finishes first. With async this is trivial and cheap, without it it’s extremely expensive and error-prone.
I wrote a fair amount of Rust code in 2012, none of it on a real project like servo. All of it just code to try to understand what the language was trying to make easy. None of that code compiles any more. (Or enough of it fails that I stopped looking at it.)
It's not so much a "critique" as it is a confirmation that when the crustaceans tell you the language definition isn't finished yet, believe them. I like the feel of Rust much more than C/C++, but I have C code I wrote in 1982 that still compiles and does what you think it should do. C++ code from 1990 still seems to compile. I have Rust code from 2014 that won't even compile.
Rust is a cool language and I hope it eventually settles down enough to be considered for "real" projects. I've done a little bit of Ada in the last year and I really, really want something better. But... reverse in-compatibility is a deal-breaker for some corners of the commercial world.
And yes, I know that (like Python) you can build an environment that lets you continue to compile old code with old compilers and some old code with new compilers. But the projects I'm talking about have life-times measured in decades. Will rustc in 2055 be able to compile a program written today? It doesn't seem to be on the top of minds of most of the Rust community.
I'm not saying Rust is ugly. In fact, I really like some aspects of the language. And post 1.0 is MUCH better than pre 1.0. But if we could go for a few years without breaking changes that would be nice.
> I hope it eventually settles down enough to be considered for "real" projects.
Rust is being deployed for real projects at pretty much every major tech company at this point, and is used on the critical path of real infrastructure.
> Will rustc in 2055 be able to compile a program written today? It doesn't seem to be on the top of minds of most of the Rust community.
This has been a very strong focus of the Rust project for a long time; the reason you saw so much breakage from 2010-2015 was to make sure that it was in the state that we'd be okay with making it stable, and then the track record from 2015 to now has been excellent. There have been a few exceptions, but they've generally been quite small, and needed for soundness fixes.
_Some_ code from 2015 still compiles today. Quite a lot of code from January 2024 won't compile today.
Turns out that in practice, the promise not to break code in the past isn't that strong, exceptions that break most of the ecosystem are "Acceptable", and the rust developers response is "Sucks for you, you'll just have to update". See:
[1] https://internals.rust-lang.org/t/type-inference-breakage-in...
[2] https://github.com/rust-lang/rust/issues/127343#issuecomment...
(Also a lot of projects that broke that day would not be broken today, because if there was a lock file, it was updated, and if there wasn’t, the new version with the fix would be selected. Only projects that had that specific dependency on time in their lock file broke.)
I keep seeing folks with this "when will Rust be ready" sentiment and it feels a bit dated to me at this point.
At my last job we built machine control software for farm equipment (embedded Linux, call it firmware if you like). The kind of thing that would have been in C or C++ not long ago. Worked great, Rust itself was never the issue. Code from the very first versions continued to work with no problems over years of feature additions, bugfixes, rewriting, edition upgrades, etc.
The job before that, my team wrote a large library of 3D geometry analysis algorithms code that powered some fun and novel CAD manufacturing tools. In Rust. Worked great. It was fast enough, and crucially, we could run it against user-provided data without feeling like we were going to get owned by some buffer overrun. 10 years earlier it 100% would have been in C or C++ and I would have been terrified to throw externally generated user data at it. We were able to do what we needed to do and it served real paying users. What more do you need?
Rust is everywhere. It's in the browser. It's in databases. It's in container/VM runtimes. It's in networking code. It's in firmware. It's in the OS. It's in application code. It's in cryptography. It's in Android. Rust is all over the place.
The only other thing I can think of with a similar combined breadth and depth of deployment to Rust on "real" projects (other than C/C++) is Java.
If I needed something to both work and be maintainable by somebody in 2055, Rust is one of the few things I'd bother to put on the list, alongside C, C++, Java, Python, and Javascript.
I've been writing Rust professionally and personally since at least 2018 and this has never happened to me.
There are plenty of real criticisms one can make about Rust (I've made and will continue to make plenty) but I think your argument would be more compelling if you updated your experience with the present-day Rust toolchain. The Rust project takes stability very seriously.
But a few years later, in 2015, Rust 1.0 shipped. So the stability really firms up from there.
I happen to have in front of me the first commit of the first modestly sized piece of software I wrote in Rust in April 2021. Which compiles today just fine and works exactly as it did when it was written, on this brand new Rust toolchain.
Sibling comments talk about a 2024 stdlib change which broke some people because they had written code which depends upon an inference and with a new enough stdlib that inference is now ambiguous so the compiler requires that you disambiguate or your code doesn't compile with the newer library.
So, that's not a breaking change in the language. It's annoying, and ideally shouldn't have happened, but in contrast the two languages you praised (C and C++) have in the last ten years made real breaking changes to their actual language and as expected the same people who insist Rust isn't "stable" shrug off the extra work from that as No Big Deal.
As someone who wrote C for decades and now writes Rust instead it's very striking how much worse the "bit rot" is in reality for C.
I'll definitely say that. It's my biggest problem with the language. Type variable declaration lists, pub keyword instead of export lists, macros instead of functors, out-of-line method declaration, special keywords and symbols all over the place that could have just been built-in type constructors, module accessor is the horrible ::, which synergies with a weird decision to nest modules extensively so that code is even noisier.
Rust is a very ugly language to me. Ugly enough that while I like many aspects of its semantic design, I will never use it personally. I would rate it to be about as ugly as Ada, just for different reasons.
The main difference here is I won't down-vote you because you say you don't like Rust.
Critical loadbearing chunks of AWS, Cloudflare, Azure and Google are built on it. It's in both the Windows & Linux kernels, shipped on billions of devices, processing probably tens or hundreds of exabytes of data every day. It's running on satellites in space and in production cars. Respectfully, you don't know what you're talking about.