Live data from Hacker News

Rust – What made it “click” for me (Ownership and memory internals)

deavid.wordpress.com

61–70 of 76 posts

Re: Rust – What made it “click” for me (Ownership and memory internals)

#61
post #41

Earlier quoted context omitted.

Problem is, it can't go where you need it to go without any concerns. There are problems doing that whether you ignore them or not. I should be able to plug whatever I want into an electrical socket and not have to worry about whether it'll start a fire, but I can't.

This is a solved problem. There are situations when the solutions don't work, but they are subject to the 90/10 rule. Or 99/1 or whatever is applicable. There are almost no application domains in which you need to conform to some insane borrowing protocol for the entire software. Your analogy is stupid beyond belief; and terms of the safety of the circuit itself that is behind the outlet, yes I can plug in anything w…

I think there might be a misunderstanding here: The analogy works precisely in that you can't plug in anything dangerous because the electrical codes make it so that dangerous things don't exist, and because circuit breakers protect you from malfunctioning stuff.

You can't plug a device that pulls 10kW into a plug and have it work, because the circuit breaker stops you from overloading your circuits. You can't plug in a device that attaches the live to your left hand and the neutral to your right, immediately stopping your heart, because such a device is forbidden by electrical codes, and everyone who makes electrical devices has to follow these.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#62
post #59
post #44

Earlier quoted context omitted.

I started learning some Rust, just begging of this yeae, and I am starting to think learning C might be the shortest path to fully understand the motivation of ownership model. But at the same time, I don't want to invest so much time into learning a language which I probably am not going to use. I am probably being disrespectful. I understand a lot of people use C, including Linux kernel devs, but I cannot imagine d…

Are you not interested in contributing to existing projects like Postgres, CPython... or being able to use the many libraries with C APIs?

Well, that sounds exciting, but I am a novice programmer from data science field. So, I am more like a user, rather than a developer.

Contributing to world class projects such as Postgres sounds cool, but doesn't it take years of experience?

Of course there are other benefit of learning C as you noted.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#63
post #60

Earlier quoted context omitted.

What other recent language is used by all large tech companies.

>"What other recent language is used by all large tech companies." What on earth constitutes "recent" language and where did you se me mentioning "resent"? Anyways, does C++17 qualify? What about PHP8, ECMAScript of latter editions, newer versions of C#, Java etc. etc. ? If I understand your thinking correct let me help you with your question: what native high performance language with no GC, memory / lifetime manage…

> What on earth constitutes "recent" language and where did you se me mentioning "resent"? Anyways, does C++17 qualify? What about PHP8, ECMAScript of latter editions, newer versions of C#, Java etc. etc. ?

No, language versions are not languages.

> If I understand your thinking correct let me help you with your question: what native high performance language with no GC, memory / lifetime management and with the stable release after 2015 is used by all large tech companies. Nice try.

I meant in general, which languages that were created in the last 20 years are used by all big tech companies.

> Also what FAANGs do with their choice of tech is their own worries. They have needs that will never be encountered by majority of the rest of the world's programming.

I was arguing that Rust is popular since it has quite a bit of adoption, as demonstrated for example by it's usage by big tech. Also, no, there is a dire need for good systems languages.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#64
post #7

> As said earlier, C++ developers have an advantage on understanding Rust because they have a mental model of what the memory looks like, pointers and so on The immeasurable success of Rust certainly lies in its clear communication and forcing developers to learn about the basics of hardware. I can't help but to feel validated in thinking that every developer worth its salt should know about these basics anyway. But…

I don't see how understanding pointers and memory layout help at all with borrowing concepts.

If you are writing C or C++ and aren't thinking about ownership and lifetimes, you have either statically allocated everything or you are doing it wrong.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#65

Personally, I'd recommend learning C to learn about the basics of memory management in higher level languages in general. It is simpler than Rust and is very transparent, making it easier to grok the concepts before moving on to something like the borrow checker, further more, it will actually make the motivations for the borrow checker and what it does to help clear. Same goes for other memory management solutions,…

I second this 100%. In the first semester of my CS degree we were only programming in C and it helped so much to understand the basics of memory. Heap, Stack, Pointers are crucial mental models which help you in nearly all programming languages.

If you are responsible for your own memory, it makes you more aware of issues such as indirection and cyclic dependencies.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#66
post #61

Earlier quoted context omitted.

This is a solved problem. There are situations when the solutions don't work, but they are subject to the 90/10 rule. Or 99/1 or whatever is applicable. There are almost no application domains in which you need to conform to some insane borrowing protocol for the entire software. Your analogy is stupid beyond belief; and terms of the safety of the circuit itself that is behind the outlet, yes I can plug in anything w…

I think there might be a misunderstanding here: The analogy works precisely in that you can't plug in anything dangerous because the electrical codes make it so that dangerous things don't exist , and because circuit breakers protect you from malfunctioning stuff. You can't plug a device that pulls 10kW into a plug and have it work, because the circuit breaker stops you from overloading your circuits. You can't plug…

Are you saying that memory management under which I can confidently any object anywhere in the program without any puerile borrowing protocols isn't safe?

Or, else, what is your point?

Re: Rust – What made it “click” for me (Ownership and memory internals)

#67
post #61

Earlier quoted context omitted.

This is a solved problem. There are situations when the solutions don't work, but they are subject to the 90/10 rule. Or 99/1 or whatever is applicable. There are almost no application domains in which you need to conform to some insane borrowing protocol for the entire software. Your analogy is stupid beyond belief; and terms of the safety of the circuit itself that is behind the outlet, yes I can plug in anything w…

I think there might be a misunderstanding here: The analogy works precisely in that you can't plug in anything dangerous because the electrical codes make it so that dangerous things don't exist , and because circuit breakers protect you from malfunctioning stuff. You can't plug a device that pulls 10kW into a plug and have it work, because the circuit breaker stops you from overloading your circuits. You can't plug…

The latter device is very easy to make with a power cord and some wire cutters & strippers though.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#68
post #61

Earlier quoted context omitted.

I think there might be a misunderstanding here: The analogy works precisely in that you can't plug in anything dangerous because the electrical codes make it so that dangerous things don't exist , and because circuit breakers protect you from malfunctioning stuff. You can't plug a device that pulls 10kW into a plug and have it work, because the circuit breaker stops you from overloading your circuits. You can't plug…

The latter device is very easy to make with a power cord and some wire cutters & strippers though.

And you can use `unsafe` in Rust, code up all sorts of memory-unsafe stuff and have it blow up in your face.

In both cases, it should be clear to you that you are behaving in a possibly dangerous manner, that you should know what you're doing and that you are responsible for not endangering others with whatever you're doing.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#69
post #61

Earlier quoted context omitted.

I think there might be a misunderstanding here: The analogy works precisely in that you can't plug in anything dangerous because the electrical codes make it so that dangerous things don't exist , and because circuit breakers protect you from malfunctioning stuff. You can't plug a device that pulls 10kW into a plug and have it work, because the circuit breaker stops you from overloading your circuits. You can't plug…

Are you saying that memory management under which I can confidently any object anywhere in the program without any puerile borrowing protocols isn't safe ? Or, else, what is your point?

I'm not saying that borrowing protocols are the _only_ way to get memory-safe programs. But aside from that, yes exactly. How memory management in C/C++/... works is not inherently safe, otherwise we wouldn't have all the memory-related bugs we have. Of course, you can write memory-safe code, but adherence to borrowing protocols can guarantee that your code is memory-safe, or at least reduce the risk by a lot.

Re: Rust – What made it “click” for me (Ownership and memory internals)

#70
post #8

Earlier quoted context omitted.

I'm not so sure that C++ gives an advantage. It's a different paradigm.

If you’re a safe c++ programmer who never writes code that has memory errors, you need to be tracking ownership and lifetimes. Once you get your head around the borrow checker, Rust takes a lot of that cognitive load off you, by tracking things for you at compile time and dinging you on it if you get something wrong.

Rust imposes a lot more constraints than just what is needed to make it safe. It imposes constraints to make it provably safe according to Rust's internal theorem prover.

I'm not convinced Rust & C++ have as much in common as you think. Rust is really familar to OCaml or Haskell users.

Post reply on HN