Bit-set as part of standard library

If the Rust foundation wants widespread adoption, it should make bit-set part of the standard library. Having a commonly used type in the leading language for competitive programming, C++, hidden behind a crate in Rust makes Rust a secondary choice for a subset of programming problems, reflecting its ease of use. If we want Rust to have widespread adoption, that includes use in competitive programming. Programming competitively in C++ and then having to switch to Rust for projects is too much juggling, which means people will chose the satisficing route of C++. Many of the best programmers program competitively for sport and not putting Rust first in that domain means they will continue to choose C++ first. Moving bit-set into the standard library improves Rusts use in competitive programming and will have the consequence of wider adoption. Likewise, whenever C++ is easier to use in the competitive domain it illustrates ease of use improvements which, if hidden behind crates, should be part of the standard library; when it is not the strictness of the compiler but the lack of functionality which makes Rust harder to use.

[Update] When I rushed posting this I thought that it was impossible to include any crates on sites like leetcode / codeforces and similar. It's not that case... you can, they just support some crates and not others. I disagree with my original posting but will leave it here for people who have similar queries.

If your competitive programming site doesn't include any crates -- such as regex -- then you should find a new site.

3 Likes

I’m not very familiar with competitive programming myself, but just doing a quick internet search makes me believe that competitive programming competitions do generally allow more than just the “standard library” for other languages, e.g. C++ or Python, as well.

If you do come across a competition – or website – that allows “nothing but the standard library” anyway, for every language including Rust, then IMHO that’s just a very poorly designed competition – or website.

I’d be curious if you can provide any prior art for context: what other programming languages have decided to design their standard library specifically with competitive programming in mind?

I’m convinced that the decision of what does or doesn’t go into the standard library should focus on other trade-offs than this.


For context, I’ve searched up a few instances of prior discussion of the design philosophy at play here – e.g. you can check out

Rust has a small standard library (and that's ok) • Krishna's blog

or look through discussions such as

Rust should have a big standard library and here's why - community - The Rust Programming Language Forum


If you’re a beginner and just not sure how to find the most important crates – which seems possible given your sentiment that something can be “hidden behind a crate”, a starting point could be some overview/lists like

Crate List - Blessed.rs

or

Most popular Rust libraries — list of Rust libraries/crates // Lib.rs


Regarding the bit_vec crate in particular, that crate had 4 new major version upgrades within the last year, it doesn’t necessarily seem like something we should pull into the standard library.

3 Likes

Some side notes:

  • Most in the community are no longer concerned about lack of adoption
  • The foundation doesn't drive lang/lib design, it works for the teams

On the specific topic of bit sets: if such types were to eventually be part of std, it would probably be inspired by and/or based on a successful crate. Someone would need to get the lib team on board with the idea and champion the process (design, implementation, stabilization).

Significant std additions are not a "convince/tell someone to do it and they will" type situation.

4 Likes

Codeforces is considered the top site for competitive programming, and leetcode is considered one of the top sites for code interview problems. Sure, maybe migrate to a different site but then the quality and quantity of the problems is diminished.

I believe the Google AI gives an incorrect answer to the question for leetcode and codeforces, neither of which support importing crates. These are top websites, not poorly designed, importing is a 'fairness' concern and they cut costs by not having to store or load external crates. Sure, designing the language to meet competitive programming concerns is a weak reason to make changes, especially if adoption is not much of a concern. My point is ease of use for competitive programming for wider adoption, which improves the number and quality of the user base for Rust. Another example is 'next_permutation', which is easy and useful in C++, but Rust doesn't have that functionality to my knowledge. Anyway, my point is C++ is top dog in competitive programming for a reason. I like Rust more, but for some problems C++ has very convenient functionality. If the aim of Rust is to replace C++, it should replace C++ in competitive programming...

I respect that. The quality of the language is important. Every language has different strengths which afford themselves to different problems. I still think C++ is top dog for competitive programming, for the reason that it has a lot of useful functionality that affords itself to those types of problems. Designing Rust around competitive programming would be stupid, but ensuring it can easily solve relevant problems to computing, like those found in competitive programming problems would strengthen the standard library; in my opinion.

What’s that? I’ve looked through official documentation of 2-3 of the notable competitions that I could find listed on Wikipedia, why would you assume AI?

Not correct. Leetcode does support rand and regex.

Why don’t they offer any more crates? I don’t know, but it seems to be their free choice as a platform, not any technical limitation that Rust imposes. Do note that there is no difference in “cost” to providing an environment with a set of crates, or one with a (hypothetical) huge standard library that would offer all that functionality.

As a datapoint, consider the playground – https://play.rust-lang.org/ – which offers over 100 crates, but executing code snippets there isn’t slowed down by that.

Rust does not aim to replace C++. Rust is Rust, and C++ is C++; each has their contexts and use-cases.

2 Likes

I don't know why I thought that. I saw it when I searched for it, and it said leetcode does support crates, which as you pointed out is actually true. I tried a couple of crates, asked ChatGPT (which said it doesn't lol.) Anyway, my post was kind of based on the assumption that leetcode / codeforces and similar sites don't support crates, which that being a reason to change the Rust language I don't agree with my original posting because I was running on bad information about how those sites work. I should have verified before posting, thought I was thorough but wasn't.. It's more an issue with leetcode and codeforces and similar sites to illustrate commonly used crates that are used in that context.