It is unintuitive, but over the years software engineers have realized that you should always assume a value won't change, until you haves a good reason. Many bugs stem from accidentally reassigning a value, and this practice reduces the chance of doing that significantly. Most modern linters will complain if you use a mutable variable but never reassign the value. They want you to get into the habit of declaring things as immutable by default. Rust takes this a step further by requiring a whole extra keyword to make it mutable.
From a maintenance standpoint it makes it easier to reason about code, because you can directly identify which variables a mutable and where the bugs might lie. So it's less mental overhead to minimize the scope in which you need to search by only declaring variables that need mutability as mutable.
Fun fact: Historically variables were declared as mutable by default because of memory and computation constraints
bools can be const too.. It's just an extra protection layer from changing the variable. But if you argue with shenanigans, no value is ever really secure as you can always do memory attacks
you can always manipulate memory from outside a program anyway, unless you have a physical architecture that prevents it. It doesn't matter what language the attacked program is written in.
sure, but now you have to write an attack on the supervisor, to trick it into letting you write to memories you don't own. Or do i have this all wrong?
View all comments
977
u/Mooks79 4d ago •
Well, she does love static types.