The Unix Heritage Society mailing list
 help / color / mirror / Atom feed
From: Dan Cross <crossd@gmail.com>
To: Bakul Shah <bakul@iitbombay.org>
Cc: TUHS main list <tuhs@minnie.tuhs.org>
Subject: Re: [TUHS] The UNIX Command Language (1976)
Date: Tue, 1 Dec 2020 16:24:43 -0500	[thread overview]
Message-ID: <CAEoi9W63J0HKbWUk8wrGSkCdyzzaV-F6km-q+K-H2+kvURWWdQ@mail.gmail.com> (raw)
In-Reply-To: <67EE6390-7E60-442B-AEEA-17951ED759A5@iitbombay.org>

[-- Attachment #1: Type: text/plain, Size: 3344 bytes --]

On Tue, Dec 1, 2020 at 3:40 PM Bakul Shah <bakul@iitbombay.org> wrote:

> On Dec 1, 2020, at 12:20 PM, Steffen Nurpmeso <steffen@sdaoden.eu> wrote:
> > Never without my goto:, and if it is only to break to error
> > handling and/or staged destruction of local variables after
> > initialization failures.  Traumatic school impression, finding
> > yourself locked in some PASCAL if condition, and no way to go to.
>
> Pascal had goto.


Pascal also had to go. (Thanks...I'm here all week.)

You can even do a non-local goto!
>
> In Go you don't need goto for the sort of thing you and McVoy
> talked about due to its defer statement and GC. Now granted
> GC may be too big of a hammer for C/C++ but a future C/C++
> add defer gainfully as the defer pattern is pretty common.
> For example, mutex lock and unlock.
>

C++ has had something analogous for some time: destructors that run when an
object goes out of scope. Scope guards to do things like close files and
auto-release locks on exiting a critical section are pretty common in that
world, and in general, preferable to many of the alternatives (either
deeply nested conditionals or banks of labels and `goto fail1;` `goto
fail2;` etc, that successively release resources on return; the latter is
basically hand-rolling what the language does automatically for you, and
has been the cause of at least security-related bug: apple's "goto fail"
bug in their SSL implementation).

There's still no easy way to break out of nested loops, though.

But I have mixed feelings about goto vs continue/break. A nested
> loop with multiple continue/break can be as obscure.
>

I submit that it's in how you write it: if the set of conditions on which
one would break/continue are explicit and early in the loop body, it can be
a very expressive way to write something. But like any tool, it can be
abused.

Along those lines, it's always been interesting to me the way that
Dijkstra's statement about goto must have influenced language design. The
original "GOTO Statement Considered Harmful" note was quite damning, but I
wonder if it meant to be: it strikes me that the really dangerous thing
about "goto" isn't its mere existence or even its use, but rather, it's
unconstrained use when better alternatives exist in the language. As one
can observe in well-written C code, judicious use of `goto` can be quite
elegant in comparison to the alternative.

I've often wondered whether  language designers, mindful of the pitfalls of
`goto`, eventually took the most useful patterns of its usage and extracted
them to stand on their own. Early returns from functions are an obvious
example, but so are `break` and `continue` and one might argue exceptions
fall into the same category. It strikes me that as we gain ever greater
experience with languages, we find more and more examples of things one
routinely does using a blunt instrument like goto, and we refine those to
first-class features of the language.

I think it's also illustrative of how social pressure can influence one to
avoid "dangerous" patterns in favor of these language features. C isn't
inherently more dangerous because it has a goto statement and labels; most
of the time, one doesn't bother to use goto because alternatives exist that
are more natural and fill the same role (continue, break, return, etc).

        - Dan C.

[-- Attachment #2: Type: text/html, Size: 4361 bytes --]

  reply	other threads:[~2020-12-01 21:26 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30  3:10 Joachim via TUHS
2020-11-30  8:30 ` Thomas Paulsen
2020-11-30 13:36 ` Brantley Coile
2020-11-30 15:12   ` Tom Ivar Helbekkmo via TUHS
2020-11-30 15:52 ` Clem Cole
2020-11-30 16:25   ` Dan Cross
2020-11-30 16:38     ` Warner Losh
2020-11-30 16:41       ` Dan Cross
2020-11-30 16:37   ` Larry McVoy
2020-11-30 16:54     ` Clem Cole
2020-11-30 18:13       ` Theodore Y. Ts'o
2020-11-30 18:25       ` John Cowan
2020-11-30 18:37         ` Clem Cole
2020-11-30 20:11           ` arnold
2020-11-30 21:49             ` Will Senn
2020-12-01  2:55             ` Jon Steinhart
2020-11-30 18:46         ` Nemo Nusquam
2021-02-10 20:48       ` [TUHS] troff was not so widely usable (was: The UNIX Command Language (1976)) Greg A. Woods
2021-02-10 21:44         ` Larry McVoy
2021-02-10 22:05         ` Clem Cole
2021-02-11 21:58           ` Greg A. Woods
2021-02-12  5:22             ` George Michaelson
2021-02-12 22:13             ` Dave Horsfall
2021-02-12 22:18               ` Ron Natalie
2021-02-10 22:36         ` Jon Steinhart
2021-02-10 23:05           ` George Michaelson
2021-02-11  0:27             ` Ron Natalie
2021-02-11  0:36               ` Larry McVoy
2021-02-11  1:53               ` Clem Cole
2021-02-11  1:59                 ` Richard Salz
2021-02-11  2:04                   ` George Michaelson
2021-02-11  2:44                     ` Richard Salz
2021-02-11  3:02                       ` Steve Nickolas
2021-02-11  4:07                         ` Toby Thain
2021-02-11 16:55                       ` Ron Natalie
2021-02-11 20:27                         ` John Cowan
2021-02-11  2:30                 ` [TUHS] troff was not so widely usable Mary Ann Horton
2021-02-11  2:52                   ` Larry McVoy
2021-02-11  6:42                     ` Andrew Hume
2021-02-11  7:12                       ` Rob Pike
2021-02-11 13:06                         ` John Gilmore
2021-02-11 17:34                           ` Jon Forrest
2021-02-11 18:09                             ` John Cowan
2021-02-11 18:43                               ` Rich Morin
2020-12-01  3:59 ` [TUHS] The UNIX Command Language (1976) jason-tuhs
2020-12-01  4:03   ` Jon Steinhart
2020-12-01  9:27   ` Steve Nickolas
2020-12-01 15:09   ` Jim Capp
2020-12-01 15:35     ` Toby Thain
2020-12-01 15:38     ` arnold
2020-12-01 16:24       ` Warner Losh
2020-12-01 16:39         ` arnold
2020-12-01 20:13           ` Rob Pike
2020-12-02  7:08             ` arnold
2020-12-02  7:29               ` Rob Pike
2020-12-01 20:20           ` Steffen Nurpmeso
2020-12-01 20:39             ` Bakul Shah
2020-12-01 21:24               ` Dan Cross [this message]
2020-12-01 23:44                 ` John Cowan
2020-12-12 19:50           ` scj
2020-12-01 16:47         ` Larry McVoy
2020-12-01 20:13     ` Dave Horsfall
2020-12-01 20:49       ` John Cowan
2020-12-01 16:04 ` Tyler Adams
     [not found] <CAMP=X_mO9oawUpHGOvgVtwVTgcmvdXAc5vrE_+s3d2NsH+1HgA@mail.gmail.com>
2020-12-01  0:00 ` Joachim via TUHS
2020-12-01  0:21   ` Dave Horsfall
2020-12-01  2:23     ` Larry McVoy
2020-12-01  3:13 Norman Wilson
2020-12-02  0:31 ` George Michaelson
2020-12-02  1:06   ` Adam Thornton
2020-12-02 17:02     ` John Cowan
     [not found] <CAKH6PiWA2uN4m0AGp7VRJTQ6XXDLJQweHoHjx2wN=zQYs1onpA@mail.gmail.com>
2020-12-03 20:31 ` M Douglas McIlroy
2020-12-03 20:37   ` Niklas Karlsson
2020-12-03 20:43     ` Larry McVoy
2020-12-03 20:56       ` Ralph Corderoy
2020-12-03 21:01       ` Ben Walton
2020-12-03 21:12       ` Clem Cole
2020-12-04  0:29       ` Dave Horsfall
2020-12-04  0:43         ` Rob Pike
2020-12-04  0:48           ` Larry McVoy
2020-12-04  1:25           ` Dan Cross
2020-12-04  9:27             ` arnold
2020-12-04 11:33               ` Andy Kosela
2020-12-04 13:14                 ` Tyler Adams
2020-12-04 13:17                   ` Niklas Karlsson
2020-12-04 13:22                     ` Tyler Adams
2020-12-04 13:25                       ` Niklas Karlsson
2020-12-04  0:45         ` George Michaelson
2020-12-04  1:10         ` Bakul Shah
2020-12-04  1:17           ` George Michaelson
2020-12-03 20:51     ` M Douglas McIlroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAEoi9W63J0HKbWUk8wrGSkCdyzzaV-F6km-q+K-H2+kvURWWdQ@mail.gmail.com \
    --to=crossd@gmail.com \
    --cc=bakul@iitbombay.org \
    --cc=tuhs@minnie.tuhs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).