News for hackers. Stuff that matters.
Re:Banned C standard library functions in Git source code by chris_wot on Sunday August 25, 2019 @12:03PM (#20793671)
I've always wondered why goto is actually considered harmful. I really should read the original paper by Djikstra...
Re:Banned C standard library functions in Git source code by GrumpyYoungMan on Sunday August 25, 2019 @02:09PM (#20794481)
Read David Tribble's "Go To Statement Considered Harmful: A Retrospective" instead: http://david.tribble.com/text/goto.html . It contains the entire text of Dijkstra's paper and goes over its meaning in a modern context on a paragraph-by-paragraph basis. It's very well written and makes clear the "encourages spaghetti code" argument, while true at the time, applied in a era where basic control flow constructs that we now take for granted did not exist in commonly used languages.
Re:Banned C standard library functions in Git source code by nybble41 on Monday August 26, 2019 @12:46PM (#20801349)
Thank you for the recommendation; that was a very interesting read. I find that I can't quite agree with the last "nontrivial goto" example, though. This version without explicit gotos is actually shorter, and IMHO not really any more difficult to follow:

    int parse(void)
    {   
      Token tok;
      while ((tok = gettoken()) != END)
      {   
        while (!shift(tok))
          if (!reduce(tok))
            return ERROR;
      }
      return ACCEPT;
    }
I will say that any language without goto, or where the use of goto is discouraged, should at least provide guaranteed tail-call elimination as an alternative. In this case the gotos could easily be converted into loops, but not every algorithm is so accommodating.
Re:Banned C standard library functions in Git source code by gbacon on Monday August 26, 2019 @09:25AM (#20799657)
See also Structured programming with go to statements[0] by Donald E. Knuth.

[0]: https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.103...

Re:Banned C standard library functions in Git source code by saagarjha on Sunday August 25, 2019 @01:35PM (#20794254)
It encourages spaghetti code.
Re:Banned C standard library functions in Git source code by Someone1234 on Sunday August 25, 2019 @02:06PM (#20794470)
Not using it can also create spaghetti code. For example the "alternatives" often suggesting for exiting a multi-tiered loop (which often add additional boilerplate, additional variables, etc that all need to be maintained/bug free).
Re:Banned C standard library functions in Git source code by FartyMcFarter on Sunday August 25, 2019 @02:13PM (#20794503)
Indeed. Despite not having actual goto, Java went out of their way to have labeled loops and the "break label_name" syntax in order to avoid this awkwardness.
Re:Banned C standard library functions in Git source code by jjuhl on Sunday August 25, 2019 @03:09PM (#20794851)