• Re: goto is silly

    From Lawrence D'Oliveiro@21:1/5 to Julieta Shem on Sat Dec 30 20:42:18 2023
    On Sat, 30 Dec 2023 17:17:07 -0300, Julieta Shem wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    On Fri, 29 Dec 2023 23:22:53 -0300, Julieta Shem wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    Arbitrary gotos:
    -- useful/desirable? Not so.

    Very useful, very desirable.

    Come on ... you don’t mean you code that way, do you?

    I do and, of course, I'm not the only one.

    Knuth, Donald E. ``Structured programming with /go-to/ statements.''
    ACM Computing Surveys (CSUR) 6.4 (1974): 261-301.

    Frankly, I don’t know how realistic his examples were: all I can say is, dynamic memory allocation was a lot less common in his day.

    Here’s my exposition on goto-free programming, and why it’s such a good idea: <https://gitlab.com/ldo/a_structured_discipline_of_programming/>.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Lawrence D'Oliveiro on Sun Dec 31 06:41:35 2023
    On 2023-12-30, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
    On Sat, 30 Dec 2023 17:17:07 -0300, Julieta Shem wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    On Fri, 29 Dec 2023 23:22:53 -0300, Julieta Shem wrote:

    Lawrence D'Oliveiro <ldo@nz.invalid> writes:

    Arbitrary gotos:
    -- useful/desirable? Not so.

    Very useful, very desirable.

    Come on ... you don’t mean you code that way, do you?

    I do and, of course, I'm not the only one.

    Knuth, Donald E. ``Structured programming with /go-to/ statements.''
    ACM Computing Surveys (CSUR) 6.4 (1974): 261-301.

    Frankly, I don’t know how realistic his examples were: all I can say is, dynamic memory allocation was a lot less common in his day.

    Here’s my exposition on goto-free programming, and why it’s such a good idea: <https://gitlab.com/ldo/a_structured_discipline_of_programming/>.

    There is a fundamental difference between goto and using control
    structures. Control structures nest, and so they avoid producing
    program control flow graphs that have certain undesirable properties,
    which is not guaranteed with goto.

    For instance control structures will not produce a graph that is
    analogous to what we get from this:

    if (condition_a) {
    // ...
    label:
    statement;
    // ...
    }


    if (condition_b) {
    // ...
    goto label;
    }

    The feature here is that we have a backwards branch, but it's not
    exactly an ordinary backwards branch. A backwards branch normally goes
    back to a node which was necessarily visited on the way to the branch.

    The branch above goes to a node which is not necessarily reached
    on the way to the goto. In fact, statement may be executing for
    the first time when the "goto label" branch is taken.

    If you banish gotos, you can guarantee to your compiler back-end
    that you don't have these kinds of branches in the program graph.
    All the backwards branches to to program nodes that dominate
    the branch points. (Meaning that the branch points are not reachable in
    the forward direction without traversing those backwards target points.)

    The Red Dragon Book discusses this (1988 edition).

    I think these kinds of odd backward gotos will also tend to
    make the logic harder to follow.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @Kazinator@mstdn.ca
    NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)