News for hackers. Stuff that matters.
Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @08:23AM (#29906006)
> My other big beef with Rust is its lack of a comprehensive stdlib, unlike Go.

I think many of us are feeling these days that the rust standard library might already be too large and it's better to be very conservative adding stuff there or only after an extended period of time of independent vetting. I have yet to not experience that standard libraries turn into very stale and outdated things relatively quickly that carries an enormous maintenance burden.

Re:Rust in 2022 by traceroute66 on Wednesday January 12, 2022 @08:36AM (#29906115)
> only after an extended period of time of independent vetting

Let's face it, what will your average dev do in the absence of something being in stdlib ?

They will (semi)randomly pick some third-party crate which in all likelihood is totally unvetted.

The crate that they selected could equally turn stale and outdated quickly if its a small one-man-band Github party (a not unfamiliar story these days).

Hence, having a standardised baseline available in stdlib is no bad thing IMHO. It brings "sane defaults" and forces anyone wanting to do different to make a thought-out decision, not just grab whatever Crate "looks good" so they can get on with coding.

Re:Rust in 2022 by berkes on Wednesday January 12, 2022 @09:43AM (#29906881)
I disagree here.

Coming from Ruby, there are lessons to be learned. Ruby has a large stdlib, like you seem to want. But a lot of stuff in there is outdated. So much, that many, even most, people, projects, frameworks immediately replace them with a community version. Sometimes because they are actually better maintained, more stable, faster, cleaner and more secure than the ones in stdlib. A similar thing is seen in Ruby-on-Rails, which adds features and even entire frameworks with every release, but which many people swap out for their own preferred lib almost immediately.

This is inevitable and obvious. And, IMO should be embraced: deprecate them from stdlib, and leave it to "the community".

> They will (semi)randomly pick some third-party

Again good lessons can be learned from Ruby (gems) here. People will pick a "random" one only if there are no canonical, defacto-standard libs (gems) out there. But for some gems there is a clear, singular goto option and everyong will pick that, turning it into something of a stdlib. A good next step would, IMO, NOT be to then pull those libs into the stdlib, but, instead, to make the "not-fully-stdlib-but-also-not-random-community-provided" into a distinct category of libs.

Re:Rust in 2022 by bydlocoder on Thursday January 13, 2022 @04:15AM (#29918531)
Ruby standard library is such a mess. It had like two YAML serializers at some point, right? dbm and gdbm (whatever they are)? Multiple prime number generators? Rinda (what the hell is this)? RSS? Xmlrpc? So, they had time to put in all that crap while failing to design a usable HTTP client.
Re:Rust in 2022 by dragonwriter on Wednesday January 12, 2022 @05:43PM (#29913794)
> Coming from Ruby, there are lessons to be learned. Ruby has a large stdlib

And is very aggressively moving stuff out of stdlib to three concentric circles of gems; “default gems” which are almost like stdlibs (and still tied somewhat to Ruby versions) but are separately maintained and can be updated between Ruby versions, “bundled” gems that are usually distributed with Ruby, and just plain regular gems.

Re:Rust in 2022 by berkes on Thursday January 13, 2022 @01:39PM (#29924731)
Indeed. And this is one of those "lessons learned".
Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @08:42AM (#29906160)
> They will (semi)randomly pick some third-party crate which in all likelihood is totally unvetted.

That's okay though. It's better for some devs to (temporarily) pick some bad crates than to permanently include some broken legacy APIs in the standard library that need to stay there due to compatibility issues. Even Python 3 couldn't get rid of a lot of code that just should not be in the standard library.

Re:Rust in 2022 by ericbarrett on Wednesday January 12, 2022 @09:15AM (#29906536)
I disagree quite strongly. A bad stdlib API can be deprecated; a bad crate bitrots. You won't see the situation so clearly at first, but after a few years you will find that an increasing number of useful crates no longer compile without intervention because direct or transitive dependencies no longer exist.
Re:Rust in 2022 by mplanchard on Wednesday January 12, 2022 @09:41AM (#29906859)
Rust commits much more strongly to backwards compatibility than a language like Python. Deprecating something in the stdlib would be a big deal.

The fact is that in practice, for most “standard” functionality that isn’t in the stdlib, there are well maintained, well vetted crates written by well known authors (or even developers of the stdlib). These are not hard to find, either by asking around or looking at what other crates use.

Rust’s stdlib is consistently of high quality. I can use everything in it without worry or concern. I can’t say the same about Python.

Re:Rust in 2022 by ericbarrett on Wednesday January 12, 2022 @10:09AM (#29907333)
Rust has already deprecated stuff in stdlib, though. It gets tagged as deprecated, and an alternative is generally provided, but the deprecated function sticks around so that stuff that uses it doesn't break. Seems like the best solution to me.
Re:Rust in 2022 by mplanchard on Wednesday January 12, 2022 @10:19AM (#29907517)
Yeah this is true, but to my knowledge that’s never been done since 1.0 with an entire module, just certain functions (could be wrong, but I have never seen it).

Keeping deprecated functions around still requires some maintenance burden, because you can’t break them just because they’re deprecated. That maintenance burden might become pretty extreme if we’re talking about something as complicated as an HTTP server module, as some folks are asking for in this thread.

I also personally don’t want to see the standard library littered with failed and deprecated experiments. In addition to the maintenance burden, it adds confusion when you’re learning the language or trying to discover how to do something.

Re:Rust in 2022 by skavi on Wednesday January 12, 2022 @08:50AM (#29906236)
> The crate that they selected could equally turn stale and outdated quickly if its a small one-man-band Github party (a not unfamiliar story these days).

Yes, but the crate dev likely offers no maintenance guarantees.

A bad stdlib had to be maintained forever (and potentially divert new users from better options)

Re:Rust in 2022 by bydlocoder on Thursday January 13, 2022 @06:37PM (#29928576)
I mean, look at Java Futures and Streams API. Like, who the hell designed this crap? Didn't they have C# and Scala to rip-off? And it's stuck forever.
Re:Rust in 2022 by tempest_ on Wednesday January 12, 2022 @09:17AM (#29906550)
It doesn't have to be.

Code can be deprecated but it is often a long drawn out process.

Re:Rust in 2022 by hiptobecubic on Wednesday January 12, 2022 @09:32AM (#29906728)
Python has been at it for most of my career.
Re:Rust in 2022 by afavour on Wednesday January 12, 2022 @09:55AM (#29907094)
> They will (semi)randomly pick some third-party crate which in all likelihood is totally unvetted.

It doesn't have to be that way, though. Why can't there be first-party crates? If the Rust core team is adding functionality to stdlib why can't they add functionality to a crate instead? Then you'd have a collection of first-party, vetted crates for devs to choose from.

Re:Rust in 2022 by moonchrome on Wednesday January 12, 2022 @09:10AM (#29906483)
The difference between having something in the standard library vs shipping it as a crate is evolution not vetting, you can have the same people develop/vet a third party crate the same as it would be if it was a part of the standard library.

The big difference is versioning (eg. you can have a crate that works on old compilers/stdlib, you can pull an older package version to new compiler/stdlib) and maintenance burden.

Re:Rust in 2022 by zibzab on Wednesday January 12, 2022 @08:43AM (#29906164)
> They will (semi)randomly pick some third-party crate which in all likelihood is totally unvetted.

That this is the norm for a language that focuses on security is mind-boggling.

Didn't we learn anything from the NPM mess?

Re:Rust in 2022 by jrimbault on Wednesday January 12, 2022 @08:35AM (#29906110)
I really like this tweet[1], which is bit cheeky, but gets also at the issue that everyone "basic" needs are actually different.

[1]: https://twitter.com/steveklabnik/status/1367854800193413126

Re:Rust in 2022 by Macha on Wednesday January 12, 2022 @09:48AM (#29906977)
To be fair, C++ has std::map and iostream/printf, so two of the examples given here as "in Rust's standard library and not in C++'s" are wrong.

Now there are reasons many people choose not to use the built in C++ std::map, and very nearly this ended up the case for Rust's HashMap, until they switched the implementation to the crate that was becoming popular. But even there's design decisions, like Rust using more compute to have a strong hash to avoid DoS attacks, that some may feel are inappropriate for their use cases.

Re:Rust in 2022 by jcranmer on Wednesday January 12, 2022 @12:09PM (#29909599)
You probably mean std::unordered_map, not std::map. std::map is a red-black tree, so it's akin to TreeMap in Java or BTreeMap in Rust. (It really is a shame that the smallest name for an associative array in C++ is for the version that is the least useful).
Re:Rust in 2022 by benschulz on Wednesday January 12, 2022 @08:53AM (#29906271)
I wish there was an `Either` type in std. I realize that there used to be one and we have `Result` now. However, now that we have `impl Trait` it's worth revisiting, I believe. If we don't we'll have the one from `itertools`, the one from `futures` etc.

In most GCed languages it wouldn't matter so much because you'd return a boxed `Iterator` or `Future` or what have you. But in Rust you generally want to avoid the allocation.

Re:Rust in 2022 by paavohtl on Wednesday January 12, 2022 @09:53AM (#29907054)
IMHO most of the time it's better to create a special 2-case enum for your specific use case. It's 3 lines of code, which gives you significantly clearer naming than "Either" and "Left/Right".
Re:Rust in 2022 by throwaway6734 on Wednesday January 12, 2022 @09:31AM (#29906722)
I ran into this recently and solved the problem via Enums. Not sure of the performance impact.
Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @09:01AM (#29906366)
I think most people end up regretting code that users itertools::Either at the moment and use it reluctantly.
Re:Rust in 2022 by benschulz on Wednesday January 12, 2022 @09:12AM (#29906513)
Can you expand on that? As long as the public type is opaque I don't see what there is to regret.
Re:Rust in 2022 by zaarn on Wednesday January 12, 2022 @10:40AM (#29907878)
As someone with difficulties telling left and right apart, using Either isn't particularly straight forward. This plus the left and right variant become meaningless on their own.

Ie, if I wanted an enum of either a string or an integer, it becomes "Either<&str, i64>".

But what I wanted is that it's either a string identifier or the database Id of something to be later referenced, which might be better described as "enum IdentOrDbId { Ident(String), DbId(i64) }".

This is of course a much simplified example of things I've faced.

Re:Rust in 2022 by benschulz on Wednesday January 12, 2022 @11:25AM (#29908761)
Sorry, based on the replies I'm getting I did not make myself clear. I only want to use Either in cases like the following.

    fn some_func() -> impl SomeTrait {
        if some_condition {
            Either::Left(a)
        } else {
            Either::Right(b)
        }
    }
Both a and b will implement SomeTrait which is all callers care about. However, because they're structurally different they must be wrapped in an Either that delegates all methods from SomeTrait to a or b respectively.
Re:Rust in 2022 by codeflo on Wednesday January 12, 2022 @11:45AM (#29909175)
I don't think that would work in general: trait methods can have signatures for which you can't synthesize an implementation for the sum type (something that takes a second Self as an argument, like std::ops::Add, comes to mind).

For object-safe traits where this would be possible, you can at least do this at the cost of an allocation, as you probably know:

  fn some_func() -> Box<dyn SomeTrait> {
      if some_condition {
          Box::new(a)
      } else {
          Box::new(b)
      }
  }
Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @11:35AM (#29908985)
The moment you have an Either::Left(Either::Left(x)) you're starting to revisit everything. Yet that's what happens with impl Iterator a lot when you have branches.
Re:Rust in 2022 by wheelerof4te on Wednesday January 12, 2022 @09:25AM (#29906643)
Oh, what will people do if there's no library for their little snowflake problem?

How could you ever possibly, gasp, write it yourself? Oh the horrors of computer science.

Seriously, many times I find myself needing only a fraction of some provided library.

Re:Rust in 2022 by JabavuAdams on Wednesday January 12, 2022 @09:35AM (#29906768)
They will be unproductive. Yeah, it's fun to micro-obsess over some hand-rolled code. Save that for side projects, or maybe you can do it if you're dev cog N+1, N > 20.
Re:Rust in 2022 by JabavuAdams on Wednesday January 12, 2022 @12:16PM (#29909734)
I'd be interested to know the distribution of sizes of organizations that write software. What proportion of all software development orgs are < 5 devs, < 10 devs?
Re:Rust in 2022 by berkes on Wednesday January 12, 2022 @09:48AM (#29906965)
> needing only a fraction of some provided library.

In a compiled language like Rust, that should not matter, isn't it? The binary-size, performance or attack-surface should not increase from code that is unused as it won't be in the resulting binary. Or did I understand it completely wrong?

Re:Rust in 2022 by christophilus on Wednesday January 12, 2022 @10:00AM (#29907185)
> I have yet to not experience that standard libraries turn into very stale and outdated things relatively quickly that carries an enormous maintenance burden

Maybe. I think .NET's core libs are excellent. So are Go's. I'm sure it's a maintenance burden, but man... It's so nice to be able to build a project with maybe 1-2 dependencies instead of 100s (as in my typical Node and Ruby projects, if you count transitive dependencies). It's hard to overstate how much of a strength I think a good stdlib is.

Re:Rust in 2022 by flippinburgers on Wednesday January 12, 2022 @08:24AM (#29906015)
Golangs stdlib is very nice to work with.
Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @08:26AM (#29906032)
I don't disagree, and so was Python's standard library in 2003. The issue with standard libraries is that the moment they move past algorithms, data structures and basic IO they are often not lasting for more than 5 years.

Even the Go standard library is quickly aging as contexts were not around when it was first created. It will be interesting to see how Go's standard library is going to evolve with Generics and more reliance on contexts.

Re:Rust in 2022 by wheelerof4te on Wednesday January 12, 2022 @09:28AM (#29906697)
Python, the language, is easy to learn. It's stdlib is not.

I agree that we need a serious refactoring of Python's stdlib.

Re:Rust in 2022 by berkes on Wednesday January 12, 2022 @09:49AM (#29906987)
> serious refactoring of Python's stdlib.

My hands start to sweat at the idea of this becoming The Python 4 Debacle.

Re:Rust in 2022 by wheelerof4te on Wednesday January 12, 2022 @09:50AM (#29907016)
Language semantics != stdlib.
Re:Rust in 2022 by berkes on Thursday January 13, 2022 @01:38PM (#29924714)
It doesn't matter why a new version would be very backwards-incompatible. Whether that is language semantics (2->3) or deprecation and replacement of stdlib (3->4 ?)
Re:Rust in 2022 by zibzab on Wednesday January 12, 2022 @08:39AM (#29906128)
> Even the Go standard library is quickly aging

If anything, I found go stdlib to age like fine wine. It doesn't do everything under the sun, but what it does it does very well and can easily be extended if needed.

Re:Rust in 2022 by yjftsjthsd-h on Wednesday January 12, 2022 @09:27AM (#29906668)
I think the argument was that Go is still too young to make that argument in the long view.
Re:Rust in 2022 by tptacek on Wednesday January 12, 2022 @04:12PM (#29912730)
Well, the time threshold given above was 5 years. It's been 10 since 1.0.
Re:Rust in 2022 by gameswithgo on Wednesday January 12, 2022 @08:35AM (#29906111)
Yes, and it makes sense for Go to have a stdlib like this, but does it make sense for Rust? You wouldn’t use Rust unless you were aiming for low level optimizations all the time, making one size fits all standard libraries less appropriate.

There is no need to make Rust like Go, Go is already a great Go.

Re:Rust in 2022 by oleganza on Wednesday January 12, 2022 @08:45AM (#29906187)
This has nothing to do with the properties of Go/Rust as languages, but all about organizational structure. Go is supported by Google who can put necessary resources to include a bunch of high-level batteries in the stdlib and keep it coherent. Rust community does not have such resources and even if there are some big players joining the community, they don't own Rust and won't be able allocate resources for continuous support without a proper org structure that allows this to be sustainable and efficient.

Philosophical reasoning like "Rust should have small stdlib" is horseshit. Ideal language has every function perfectly designed in the stdlib (kinda like PHP in 2003, lol). But to get closer to that dream you need some sustainable organization that maintains and expands that stdlib, wishes to do so and has resources to do that continuously.

If it's just random 5 people doing maintenance and hacking at their spare time, that's not enough for an expanding library of diverse code. That could be enough only for keeping very core features working/improving like const generics and borrow checker.

Re:Rust in 2022 by the_mitsuhiko on Wednesday January 12, 2022 @09:00AM (#29906357)
> Ideal language has every function perfectly designed in the stdlib

That way of thinking only makes sense if nothing ever changes. You even bring PHP as a good example here of how this fails fast. The world has changed greatly since 2003. The Python standard library carries three XML implementations and an outdated HTML parser irrelevant for the modern world. These libraries were state of the art when they were written, but it's the world around it that changed.

Now one can make the argument: why was it not modernized and updated? The simple answer is that people started building code against this and now depend on it working this way. The only way would be to completely rewrite them with new APIs, remove stuff no longer needed but then you're effectively back to just using crates.io and the likes. Except it's worse now because the standard library is a monolith and does not compose.

Re:Rust in 2022 by hiptobecubic on Wednesday January 12, 2022 @09:40AM (#29906852)
On the other hand, code using those libraries still works, whereas code trying today's favorite parser will not work after community moves on and stops maintaining it.

I agree you don't want everything in the stdlib, but havinga stdlib way to achieve something is pretty valuable, even if it's not the best way and never was.

Re:Rust in 2022 by mplanchard on Wednesday January 12, 2022 @09:47AM (#29906955)
Why would code dependent on third party libraries break? It’s not like crates.io is going to stop hosting them when they become unmaintained. Barring security vulnerabilities, a library that does a well encapsulated task like parsing json might work just fine without updates for ten or more years.

In cases where libraries don’t keep up with changes in standards or whatever, yeah, you’re going to have to find another library. This is a part of our job that is pretty much unavoidable no matter the language. We should learn lessons like sticking dependencies you’re not certain about behind an interface to minimize the cost of switching if possible.

Re:Rust in 2022 by Macha on Wednesday January 12, 2022 @09:57AM (#29907140)
> Barring security vulnerabilities, a library that does a well encapsulated task like parsing json might work just fine without updates for ten or more years.

JSON library updates are a constant tedious chore for many in the Java world. Jackson and Gson have both had several we've needed to make over the years. Now, _most_ of these are due to non-default features where you allow it to deserialize arbitrary types that we don't use. But clients big enough to insist on a BOM and internal security teams both just see "Jackson version x.y.z has a RCE on it, you need to update", even if it's literally impossible to trigger without changing the application code to enable insecure features.

Re:Rust in 2022 by mplanchard on Wednesday January 12, 2022 @10:02AM (#29907213)
You’re right, a json parser may have been a poor choice. Perhaps something like a UUID generator, or a parser for some more well-established and stable text format would be a better example.

On the other hand, something like a json parser needing to change all the time to support the ecosystem is another good reason to keep it out of the stdlib, IMO. There are limited hands to work on Rust itself, and I’d rather they spend their time making improvements to the core of the language, stabilizing features, and so on. As a user of rust, I’m willing to pay the cost of finding a good json library if it means I don’t need to update rust versions just to deal with some issue in JSON parsing.

Re:Rust in 2022 by Macha on Wednesday January 12, 2022 @10:06AM (#29907273)
At the same time, code that is "one and done" like a uuid generator is a much lower maintenance burden for the standard library.
Re:Rust in 2022 by mplanchard on Wednesday January 12, 2022 @10:15AM (#29907450)
Very true! I think the philosophy of letting external crates handle it and seeing how stable they are before considering inclusion in the stdlib is a good one here. Maybe in a few years we see that the uuid crate never needs updates and is super stable, so someone opens an RFC to pull it into std.

The thing is it’s easy to be wrong if you’re trying to predict up front what is going to wind up being stable and low maintenance and what isn’t, so the precautionary nature of what gets into the stdlib I think reflects that.

Re:Rust in 2022 by bydlocoder on Thursday January 13, 2022 @06:23PM (#29928451)
Lol, I do remember how an upgrade of a JSON serializer (JSON.NET in that case) broke an application. So, there was a .NET service publishing events to a queue with a bunch of consumers - a bunch of Golang service and (our) Scala service. One day our service starts crashing cause it can't parse the payload. We asked developers of the upstream service if they had change anything and they said "no, and by the way, other consumers are doing fine".

Turns out, they upgraded JSON.NET and it started to name fields in different case. Golang parser didn't really care about snake_case, camelCase or PascalCase but whatever parser we were using in Scala at the time actually did.