← Back to context

Comment by tialaramex

3 years ago

Mutation isn't confusing. On its own. Multiple references isn't confusing. On its own.

The observation, which I don't think I saw being made twenty years ago (I could be wrong) is that you shouldn't mix these two things. No multiple references with mutation. In theory you can safely do so in serial programs if you were careful enough, in practice you won't be careful enough and we should write fewer serial programs than we do, so why not reject this outright.

Rust is one particular (and notably successful) attempt to make a programming language about this big idea, but it's the idea in Val and several other newer languages. There are a lot of unknowns about the best way to approach this, but "Just pretend it's not important" is not a correct answer.

My point was simply that at some point the buck stops and someone has to write the code to mutate a memory cell.

Regarding your point, shared xor mutable is nice, but databases are an example of a shared mutable (and even concurrent!) yet safe resource, so other models are possible.

  • > databases are an example

    Yes, it is possible because programmers have accepted the bargain that they must write purely-functional SQL.

    Then the db is able to decide how best to optimise/apply/retry/copy-on-write/abort as necessary.

    If SQL allowed you to directly mutate things, it would break everything. You couldn't 'LIMIT 10' if your loop might want to increment some data in row 40082.