Rust isn't that difficult to prototype or start projects with? What trouble do you run into? I think the hardest parts to understand are the concepts of borrowing, lifetimes, and ownership, but you don't have to know all the subtleties of that to prototype. A basic understanding is fine to get started with. Just like a developer doesn't have to understand all the subtleties of generics to get started with either, lots of devs don't know what covariant or contravariant means and use generics.
Yes, but this was on the topic of "is Rust suited for prototyping?", and I would say that cloning makes it much more suited, as it sidesteps a lot of the lifetime pains. You will have similar deferred pain if you e.g. prototype something in JS and then when it's time to move to production gradually move it to Typescript.
From personal experience of Rust projects in production, you can get by with cloning for a long time, and optimizing later is not too big of a pain in most cases. Performance problems due to excessive cloning are also very obvious in code and easy to profile for.
Could you explain to a junior what Box<dyn std::error::Error + Send + Sync + 'static> does and how should a person who is starting to learn Rust come up with something like this?
Second minor example. I have a configuration string like let's say timeout for a certain type of connection. What is the recommended way to have that as a string that is accessible to all functions without fighting with the borrow checker?
In Elixir, I would use @timeout in the module for example. In Rust, I am not sure. Cloning the value to every place it needs it as a workaround.
I get what you're trying to say, but disagree with the examples. If you want to prototype and start a project, you don't care what exactly that box type means. You can use it and things will not break. It's part of that particular boilerplate.
It's like people using `std::string` and not necessarily caring for years what `template<class CharT, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT>> class basic_string;` means or does.
For the second example: environment variable. Once you need more, you can start researching static cells and use a ready crate for configuration loading / processing. If you want more, googling "rust mutable global configuration" brought me https://stackoverflow.com/questions/27791532/how-do-i-create... which gives a pretty good solution.
>> If you want to prototype and start a project, you don't care what exactly that box type means.
I disagree. The whole point is to get to know a language. What do you how many things can you have in your code that you do not understand? Now you put it in production and it breaks. Who is going to fix it? I do not have a particulary positive experience with Rust on Stackoverflow. As a tech decision maker I put Rust in the risky category because it is hard to understand and many of the language features are implemented in a way that it is not easy to work with. Don't get me wrong, I like what Rust could bring to the table but with this upfront complexity it is not worth it. I know many companies who will be ok to take on Rust and they are ok with the way things are.
Your answer is funny to the second one. From SO:
Non-answer answer
Avoid global state in general. Instead, construct the object somewhere early (perhaps in main), then pass mutable references to that object into the places that need it. This will usually make your code easier to reason about and doesn't require as much bending over backwards.
Why would I pass in a mutable reference when all I need is a global static immutable value? You see this get ugly very quickly. We went with the lazy_static! way, but still. I would rather avoid these things entirely.
When you're actually starting up (you set the context to "someone starting to learn rust"), there will be some unknown things in any language. You'll get there, but you don't need to understand it from the beginning. If you do want to understand it, then you should get it from the official guide. Errors, dyn, box, lifetimes and send are covered.
"Value on the heap, which implements the error interface, is available forever, and can be shared between threads" is... not that complicated.
> Now you put it in production and it breaks.
If you're still learning the language and don't understand the boilerplate, you don't put your app in production.
> Why would I pass in a mutable reference when all I need is a global static immutable value?
You missed the context. The fragment was about a mutable global. If you just need an initialised, but immutable config, you pass a non-mutable reference.
A good related question is: what will be the "future" of software development? I would bet that WASM and Rust will become more and more dominant in a 5-10 years timeframe. But it's so hard to come up with an informed opinion, as many developers tend to become "religious" about their language of choice.