Live data from Hacker News

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

deavid.wordpress.com

31–40 of 76 posts

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

#31

Earlier quoted context omitted.

Ownership is completely inadequate for operating systems. Good luck with a browser without javascript.

Ironic that it came from a project in Mozilla, who used it to experiment with a new browser engine.

Yeah; I'm pretty sure parts of firefox have already been rewritten in rust. And there's a project at google to start adding rust to chromium too[1].

> Ownership is completely inadequate for operating systems.

The linux kernel is adding rust support as a first class language. In time I wouldn't be surprised if large parts of the linux kernel were written in rust. Obviously linux will always have a lot of unsafe code, but unsafe is part of rust too. Its surprising how infrequently you need it.

[1] https://security.googleblog.com/2023/01/supporting-use-of-ru...

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

#34

Ownership is a time-wasting idea; an object should be freely able to go anywhere in the program you need it to go without any concerns.

A new conception of software freedom: free from the constraints or considerations of reality. Where it’s not the code that’s unsafe, it’s the thinking about and addressing its safety that’s harmful. Kill your gods but don’t let the compiler ever figure it out!

Criticize Rust and here comes god talk in 3... 2... 1....

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

#35
post #17

Earlier quoted context omitted.

Why do you think Rust has been such a success?

It has not a success. Just aggressive ads.

Yes and no. The aggressive marketing is successfully entrenching it to future generations so whether it’s successful with the current gen of c++ programmers or even GC languages like Java doesn’t really matter imo.

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

#36
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, gc, reference counting, etc. So much of what we do is still bound to a deeply entrenched model that C established.

Ultimately we are all still just writing nicer versions of C. The fundamental model of pretty much all high level languages remains the same. You can still explain and think about the vast majority of memory related goings-on in a program as using the basic abstraction of the pointer and contiguous arrays of bytes. Even languages that have different paradigms, be they functional, logical, or object oriented can be described in terms of pointers--one easy way to understand pretty much every other programming language paradigm is basically just to ask "how would I implement this using pointers?". It's a shared history and approach to computing we have yet to move on from.

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

#37
Today I had a moment with TypeScript where I got an error because a class property wasn’t definitely initialized in the constructor.

I thought, “I wish there was a way to prove to the compiler that it will be there when I access it, rather than having to tell it to trust me.”

And that’s when lifetimes in Rust really clicked for me. I know it’s not exactly the same thing but the value of describing the valid lifetime of a thing at compile time began making a lot more sense.

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

#38
> As a rule of thumb, if you don’t want the function to consume the data (to free it), don’t ask for ownership.

As a Rust beginner, that's a handy thing to remember! Thinking of variable passing in terms of least privilege seems much better than just trying to use the simplest syntax (changing ownership by passing the variable rather than a pointer to it) all the time.

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

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

It provides historical context. Someone coming from a gc langage that has never even had to learn what memory even is wrt to a program will not understand why a borrow checker is even a thing.

You can get very far writing software without even being aware that your language is even doing something called garbage collection for you, or without even having a basic concept of memory being tied to values, sizes, etc. If you lack this context a borrow checker just seems like a pointless nuisance.

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

#40
post #20
post #9

Earlier quoted context omitted.

> not everybody comes with a CS background. Something doesn't sit quite right with me to describe the "basics of hardware" as being something that comes with a "CS background". I come from a formal CS background, and we spent more time dealing with finite state automatons, programming language theory, and other aspects of abstract computation. Getting down and dirty with data sizes, system components, and bit fiddlin…

I have a funny relationship with this. I also come from a formal CS background too. The old joke is that there are two lies in Computer Science: firstly its not science, and secondly it isn't really about computers. But the reality is, I still can't tell you what Computer Science actually is. Is it: - About understanding how to control computers (which are fast electronic machines) - About inventing programming, from…

There is also the part of CS that could be described as the science of computation.

The lines between academic fields are primarily administrative. Their main purpose is to facilitate undergraduate education. They are also fuzzy and vary between institutions. A person working in a CS department could find their home in the mathematics department at another university. Or physics. Or economics. Or biology. Or somewhere else. No matter what CS was at your university, it can be something very different at another.

Post reply on HN