Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> I suppose if you repeat this enough you learn how to write code that Rust is happy with first-time.

But this assumes that your specifications do not change.

Which we know couldn't be further from the truth in the real world.

Perhaps it's just me, but a language where you can never change your mind about something is __not__ a fun language.

Also, my manager won't accept it if I tell him that he can't change the specs.

Maybe Rust is not for me ...



I genuinely don’t know where you’ve gotten the idea that you can “never change your mind” about anything.

I have changed my mind plenty of times about my Rust programs, both in design and implementation. And the language does a damn good job of holding my hand through the process. I have chosen to go through both huge API redesigns and large refactors of internals and had everything “just work”. It’s really nice.

If Rust were like you think it is, you’re right, it wouldn’t be enjoyable to use. Thankfully it is nothing like that.


"Malum est consilium, quod mutari non potest" you might say.


My recommendation is that you do whatever you feel like with ownership when you first write the code, but then if something forces you to come back and change how ownership works, seriously consider switching to https://jacko.io/object_soup.html.


Isn't that just reinventing the heap, but with indexes in a vector instead of with addresses in memory?


You could look at it that way. But C++ programs often use similar strategies, even though they don't have to. Array/Vec based layouts like this give you the option of doing some very fancy high-performance stuff, and they also happen to play nicely with the borrow checker.


It's very basic and not a general solution because the lifetimes of objects are now set equal. And there's no compaction, so from a space perspective it is worse than a heap where the space of deleted objects can be filled up by new objects. It is nice though that you can delete an entire class of objects in one operation. I have used this type of memory management in the context of web requests, where the space could be freed when the request was done.




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

Search: