4 ms·
So you are telling me a valid optimization for Go is to elide the entire contents of all goroutines? And by that argument, since main() itself is an implicitly
by kevhito 10y ago
So you are telling me a valid optimization for Go is to elide the entire contents of all goroutines?
And by that argument, since main() itself is an implicitly-called goroutine (so far as I know), then the compiler can elide the entire contents of main() too, and then the rest of the contents of the program.
</reductio-ad-absurdum>
- NateDad 10y agoWell, sort of, yes. https://play.golang.org/p/qyfqZA5pww https://play.golang.org/p/qyfqZA5pww func main() { go fmt.Println("Hi!") } This is a valid go program (eliding import etc), and it'll almost never print anything. This is actually a classic mistake when starting with goroutines - not adding synchronization to make sure your main goroutine doesn't exit before any spawned goroutines.
- CasualSuperman 10y agoYes, but then the program would never terminate, because that's what happens at the end of main. If main returns, it's saying that the rest of the code in main has executed.