As an example, in our C++ codebase at work we always place mutex locks inside their own scope blocks along with the critical sections of code they’re synchronizing. Helps readability and the scope determines when the mutex is released.
Indeed! I somewhat over-use this in Rust to initialize an immutable variable with mutating code.
let var: Vec<u32>; // this one is immutable, will be initialized later
{
let mut var_; // mutable
… // initialize var_ with some mutating code
var = var_; // now move var_ to var, initializing the latter
}
I also abuse blocks in Rust, but it's more in order to placate the borrow checker...