Hacker News new | past | comments | ask | show | jobs | submit login

>> 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.




> The whole point is to get to know a language.

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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: