3 ms·
`finally` introduces additional blocks, so if you have 5 different resources that you acquire as your function goes along, you end up with 5 levels of curly bra
by golergka 6y ago
`finally` introduces additional blocks, so if you have 5 different resources that you acquire as your function goes along, you end up with 5 levels of curly braces. Not very elegant.
`defer`, on the other hand, is probably the only thing I wanted to take from Go to other languages I worked with. Beautifully explicit and wonderfully useful.
- shhsshs 6y agoC#’s new syntax for `using` also helps: Old: using (var file = OpenFile()) { // use file } New: using var file = OpenFile(); // file will be disposed when it goes out of scope
- earthboundkid 6y ago> `finally` introduces additional blocks It would be cool if someone made a way to scope variables at the function level in JavaScript instead of at the block level. I might write a transpiler for it…
- golergka 6y agoI've never considered writing a proposal for a language feature before, but after 2 minutes of googling, this actually looks completely doable: https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md So, impostor syndrome aside, why not? Wanna team up on that?
- earthboundkid 6y agowhoosh.gif
- golergka 6y agoOkay, it was 2am here and I must have misread your comment and lost the 'variables' part.
- jakopo87 6y agoIt is already possible: var makes a variable function-scoped, let/const makes a variable block-scoped. Or are you referring to something else?