3 ms·
Many languages have ways to reduce scope in a single function (rust: drop, c/c++ java: {}, etc) so you can have a long function that means "these things need to
by rendaw 4y ago
Many languages have ways to reduce scope in a single function (rust: drop, c/c++ java: {}, etc) so you can have a long function that means "these things need to happen in sequence" without suffering from excess shared state. Though obviously not perfect.
- sophacles 4y agoIn rust you can also do something like: let (x, y) = { ... (some code that only serves to create x and y) }; I really really like that feature for controlling scoping - it's like a single use function that doesn't involve so much navigation. Other languages allow similar constructs with blocks too. For ones that allow inline lambdas, you can also get similar results by defining and immediately calling the function.