4 ms·
As someone not versed in Virtual Machine development, is goto so important? What do you gain by using it?
by mughinn 4y ago
As someone not versed in Virtual Machine development, is goto so important? What do you gain by using it?
- c0balt 4y agoGoto is quite a powerful tool for having a full, imperative grip on control flow. It is quite often useful due it's simple yet powerful ability to "just" work. Virtual machines may often encounter situations where a tight control over the flow can be advantagous for performance etc. reasons. Goto has been iirc a point of discussion from the language design pov for Rust. I don't think it promotes good design for most applications but ymmv.
- nsajko 4y ago> What do you gain by using it? Performance, although this possibly depends on your compiler, whether you use PGO, and similar finicky issues. Example: https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e... Some prior HN discussion: https://news.ycombinator.com/item?id=18678920 https://news.ycombinator.com/item?id=18678920 Another example where goto is relevant is implementing finite automata. A (very short) paper from 1988 that discusses three different ways of implementing a finite state machine is "How (Not) to Code a Finite State Machine". The documentation of RE2C may be even more interesting: https://re2c.org https://re2c.org RE2C is a program that compiles finite automata into C, Go, or Rust code. It provides many implementation strategies: it can make use of computed or labelled gotos when the language provides them. Implementing pushdown automata comes with similar issues.