The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
* [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary
@ 2023-03-10 11:37 Noel Chiappa
  2023-03-10 11:51 ` [TUHS] Conditions, AKA exceptions. (Was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Ralph Corderoy
  2023-03-10 15:54 ` [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary Dan Cross
  0 siblings, 2 replies; 75+ messages in thread
From: Noel Chiappa @ 2023-03-10 11:37 UTC (permalink / raw)
  To: imp, segaloco; +Cc: tuhs

    > From: Warner Losh

    > In C I use it all the time to do goto err for common error recovery
    > because C doesn't have anything better.

That's because C doesn't have 'conditions'. (Apparently, from the following
posts, most people here are unfamiliar with them. Too bad, they are a great
idea. OK summary here:

  http://gunkies.org/wiki/Condition_handler

for those who are unfamiliar with the idea.)

I was at one point writing a compiler using a recursive descent parser, and
decided the code would be a lot simpler/cleaner if I had them. (If, for
example, one discovers discovers an un-expected 'end of file', there can be
an extremely large number of procedure invocations in between where that is
discovered, and where it is desirable to handle it. So every possible
intervening procedure would have to have an 'unexpected EOF' return value,
one would have to write code in every possible intervening procedure to
_handle_ an 'unexpected EOF' return value, etc.)'

(Yes, I could have used setjmp/longjmp; those are effectively a limited
version of condition handlers.)

Since C has a stack, it was relatively easy to implement, without any compiler
support: on() became a macro for 'if _on("condition_name")'; _on() was a
partially-assembler procedure which i) stacked the handler (I forget where I
put it; I may have created a special 'condition stack', to avoid too many
changes to the main C stack), and ii) patched the calling procedure's return
point to jump to some code that unstacked the handler, and iii) returned
'false'. If the condition occurred, a return from _on() was simulated,
returning 'true', etc.

So the code had things like:

	on ("unexpected EOF") {
		code to deal with it
		}

With no compiler support, it added a tiny bit of overhead
(stacking/unstacking conditions), but not too bad.

John Wroclawski and someone implemented a very similar thing
entirely in C; IIRC it was built on top of setjmp/longjmp. I don't
recall how it dealt with un-stacking handlers on exit (which mine
did silently).

    Noel

^ permalink raw reply	[flat|nested] 75+ messages in thread
* [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary
@ 2023-03-10 15:37 Noel Chiappa
  2023-03-10 15:46 ` Larry McVoy
                   ` (2 more replies)
  0 siblings, 3 replies; 75+ messages in thread
From: Noel Chiappa @ 2023-03-10 15:37 UTC (permalink / raw)
  To: tuhs

    > From: "Ronald Natalie"

    > Multilevel breaks are as bad as goto with regard to structure violation.

In a way, you are right. There isn't really much difference between:

	for (mumble) {
		for (foobar) {
			do some stuff
			break-2;
			}
		}

and:

	for (mumble) {
		for (foobar) {
			do some stuff
			goto all_loops_done;
			}
		}
	all_loops_done:


The former is basically just 'syntactic sugar' for the latter.

I think the point is that goto's aren't necessarily _always_ bad, in and of
themselves; it's _how_, _where_ and _why_ one uses them. If one uses goto's
in a _structured_ way (oxymoronic as that sounds), to get around things that
are lacking in the language's flow-control, they're probably fine.

Then, of course, one gets into the usual shrubbery of 'but suppose someone
uses them in a way that's _not_ structured?' There's no fixing stupid, is my
response. Nested 'if/then/else' can be used to write comletely
incomprehensible code (I have an amusing story about that) - but that's not
an argument against nested 'if/then/else'.

As I've said before, the best sculpting tools in the world won't make a great
sculptor out of a ham-handed bozo.

	Noel


^ permalink raw reply	[flat|nested] 75+ messages in thread
* [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary
@ 2023-03-10 11:51 Noel Chiappa
  2023-03-10 14:16 ` Ronald Natalie
  0 siblings, 1 reply; 75+ messages in thread
From: Noel Chiappa @ 2023-03-10 11:51 UTC (permalink / raw)
  To: tuhs

    > From: Warner Losh

    > for breaking out of multiple levels of while/for loops.

Yeah, multi-level 'breaks' were one of the things I really missed in C.

The other was BCPL's 'VALOF/RESULTIS'. Back before C compilers got good
enough to do inline substitutions of small procedures (making macros with
arguments less useful), it would have been nice to have, for macros that
wanted to return something. Instead, one had to stand on one's head and use a
'(cond ? ret1 : ret2 )' of some form.

       Noel

^ permalink raw reply	[flat|nested] 75+ messages in thread
* [TUHS] I can't drive 55: "GOTO considered harmful" 55th anniversary
@ 2023-03-09 23:01 Steffen Nurpmeso
  2023-03-09 23:18 ` [TUHS] " segaloco via TUHS
  0 siblings, 1 reply; 75+ messages in thread
From: Steffen Nurpmeso @ 2023-03-09 23:01 UTC (permalink / raw)
  To: tuhs

I wonder if Pink Floyd's Summer68 maybe refers to this.
Other than that i am addicted and could not live without it.
The other (terrible) song is from 1984 (east southern US).

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

^ permalink raw reply	[flat|nested] 75+ messages in thread

end of thread, other threads:[~2023-03-14 21:34 UTC | newest]

Thread overview: 75+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 11:37 [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary Noel Chiappa
2023-03-10 11:51 ` [TUHS] Conditions, AKA exceptions. (Was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Ralph Corderoy
2023-03-10 15:54 ` [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary Dan Cross
2023-03-12  7:39   ` Anthony Martin
2023-03-12 11:40     ` Dan Cross
2023-03-12 16:40       ` Paul Winalski
2023-03-13  3:25       ` John Cowan
2023-03-13 10:40         ` Alejandro Colomar (man-pages)
2023-03-13 12:19           ` Dan Cross
2023-03-13 12:43             ` [TUHS] [TUHS]: C dialects (was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Alejandro Colomar
2023-03-13 12:46               ` [TUHS] " Dan Cross
2023-03-13 16:00               ` Paul Winalski
2023-03-13 19:00                 ` Clem Cole
2023-03-13 19:09                   ` Larry McVoy
2023-03-13 19:17                   ` Steve Nickolas
2023-03-13 20:26                     ` Dan Cross
2023-03-13 22:25                       ` Alejandro Colomar (man-pages)
2023-03-13 19:24                   ` [TUHS] Re: [TUHS]: C dialects Luther Johnson
2023-03-13 19:38                     ` Luther Johnson
2023-03-14 19:48                     ` John Cowan
2023-03-14 19:56                       ` Joseph Holsten
2023-03-14 20:01                       ` Luther Johnson
2023-03-13 20:48                   ` [TUHS] Re: [TUHS]: C dialects (was: I can't drive 55: "GOTO considered harmful" 55th anniversary) Paul Winalski
2023-03-13 20:56                     ` Bakul Shah
2023-03-14  1:06                     ` Larry McVoy
2023-03-13 21:00                   ` Paul Winalski
2023-03-13 21:07                     ` Bakul Shah
2023-03-13 21:14                       ` Dan Cross
2023-03-13 22:15                         ` Dave Horsfall
2023-03-13 22:47                           ` Dave Horsfall
2023-03-14  0:23                             ` Dan Cross
2023-03-14  0:21                           ` Dan Cross
2023-03-14 13:52                             ` Chet Ramey
2023-03-14  1:27                         ` Bakul Shah
2023-03-13 21:28                       ` Paul Winalski
2023-03-14 10:04                       ` [TUHS] C dialects Ralph Corderoy
2023-03-14 20:02                         ` [TUHS] " John Cowan
2023-03-14 21:34                           ` Thomas Paulsen
2023-03-14  0:38                     ` [TUHS] Re: [TUHS]: C dialects (was: I can't drive 55: "GOTO considered harmful" 55th anniversary) John Cowan
2023-03-14  2:49                 ` Theodore Ts'o
2023-03-14  3:06                   ` G. Branden Robinson
  -- strict thread matches above, loose matches on Subject: below --
2023-03-10 15:37 [TUHS] Re: I can't drive 55: "GOTO considered harmful" 55th anniversary Noel Chiappa
2023-03-10 15:46 ` Larry McVoy
2023-03-10 16:04 ` Dan Cross
2023-03-10 18:55 ` Ron Natalie
2023-03-10 19:04   ` Dan Cross
2023-03-10 19:35     ` segaloco via TUHS
2023-03-10 11:51 Noel Chiappa
2023-03-10 14:16 ` Ronald Natalie
2023-03-10 14:39   ` John Cowan
2023-03-10 16:30   ` Phil Budne
2023-03-10 17:50     ` Steffen Nurpmeso
2023-03-10 17:57       ` Paul Winalski
2023-03-10 18:12         ` Lawrence Stewart
2023-03-10 17:28   ` Clem Cole
2023-03-10 17:54     ` Paul Winalski
2023-03-09 23:01 [TUHS] " Steffen Nurpmeso
2023-03-09 23:18 ` [TUHS] " segaloco via TUHS
2023-03-09 23:21   ` Warner Losh
2023-03-09 23:31     ` Luther Johnson
2023-03-09 23:44       ` josh
2023-03-09 23:54       ` Warner Losh
2023-03-10  0:54         ` segaloco via TUHS
2023-03-10  1:08           ` Warner Losh
2023-03-10 10:08             ` Ralph Corderoy
2023-03-10 11:37               ` arnold
2023-03-10 11:56                 ` Ralph Corderoy
2023-03-10 11:59                   ` arnold
2023-03-10 12:11                     ` Ralph Corderoy
2023-03-10  6:15     ` Dave Horsfall
2023-03-10 16:55       ` Steffen Nurpmeso
2023-03-10 17:02         ` Bakul Shah
2023-03-12 20:47         ` Dave Horsfall
2023-03-12 21:50           ` Warner Losh
2023-03-12 22:27             ` Steffen Nurpmeso
2023-03-10  1:31   ` Rich Morin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).