yes, defers run at all times, and there is an exception catching mechanism you can put inside a defer closure

in Go there is functions and closures, these are scopes for entry and exit of subroutines, then there is logic blocks like if, switch, for and select, these have scopes also that you can create new variables inside in specific ways... to make a switch execute defer-like code you would use the "fallthrough" to let the switch check all conditions and then you put your defer code in the default

go can do all the things, just not in all the ways, because actually you don't really need that much flexibility

my first two languages were BASIC and Assembler... if you can't express an algorithm in a simple form then all you are adding by this complex language construct is a big cost in deciphering your intent in this "expressive" language

go has two different types of scope, there is imperative scopes, like inside functions and logic blocks, and there is declarative, which the main one is the top level of a source file

the reason why they do it this way is that it makes cutting up the source files so much easier, you literally search for the short set of sentinels (there is about 10 or so) and then you know what is inside each one

all these fancy constructs in other languages are all well and good but you pay for them in a proportionally longer edit/test cycle time, go prioritises being able to change one line of code and test it under 5 seconds later

Reply to this note

Please Login to reply.

Discussion

Man is a Go enjoyer.

But have you ever used Forth?

bitcoin script is based on forth

when i was 12 years old i got a "work experience" time with an agricultural scientist who was making crop simulations, and his main language was forth

i learned lisp and C at the time

forth is just barely more than assembler, and BASIC is like complicated forth

there is a retarded mentality in the tech sector these days that you can reingineer mathematics somehow

STOP IT!

Forth is so fun. I played with Gforth a while back.