comp.lang.ada
 help / color / mirror / Atom feed
From: karl@haddock.ima.isc.com (Karl Heuer)
Subject: Re: problems/risks due to programming language
Date: 26 Feb 90 22:02:13 GMT	[thread overview]
Message-ID: <16039@haddock.ima.isc.com> (raw)
In-Reply-To: 5479@ur-cc.UUCP

I'm redirecting followups to comp.lang.misc.

In article <5479@ur-cc.UUCP> Michael Sullivan writes:
>[A lot of strawman arguments]

I don't think anybody is seriously arguing the position that you seem to be
attacking.  I also don't know how closely my position matches that of the
other participants in this debate, but I'll state mine as a series of claims
for you to agree with or rebut as you like.

It's meaningless to say "the `break' keyword is {good,bad}"; you have to have
an alternative to compare against.  I will use the notation `C with feature X'
to mean `a hypothetical language which is a lot like C but which has feature
X'; then we can make statements like `C with X would be a better tool than C'.

I am not arguing that C should be changed in this regard (except by adding
warning messages where appropriate).  Thus, the existence of a large body of
code written in C-as-it-is-today is not a factor in such comparisons.

We need to distinguish between keywords and the operations they denote.  It
turns out to be useful to distinguish two operations, which I will call
`break-switch' and `break-loop', both of which are denoted by the keyword
`break' (depending on context).  I will use the term `fall-through' to denote
the operation of flowing from the end of one case into the beginning of the
next one; this operation is denoted in C by the absence of a `break' keyword
in reachable flow at the end of a case block.

Claim 0.  Much use of fall-through in C is simply attaching several cases to a
single action.  (In fact, this is the `positive side' you quoted from the Holy
Scriptures.)  Some other languages achieve this by allowing multiple values to
be associated with a single case label, instead.  Thus, C with multiple valued
cases would not need fall-through nearly as often.

Claim 1.  A break-switch is rarely needed at any point other than at the end
of a case block.  At the end of a case block, break-switch is needed much more
often than fall-through.

Claim 2.  As a general principle, if there is a default action it should be
the most common of the alternatives.  This tends to minimize certain kinds of
user errors.

Definitions.  Let `CX' be the language C with multiple valued cases, with
automatic break-switch at the end of each case block, and with the `break'
keyword denoting only the break-loop operation.  `CX with jumpcase' is CX
with an explicit keyword to denote the fall-through operations (overriding the
default behavior of an automatic break-switch).

Claim 3.  CX with jumpcase would be better than C.

Claim 4.  CX itself would be better than CX with jumpcase (and hence better
than C); the extra keyword doesn't buy you enough to be worth adding, and it
would destroy the commutativity of case blocks, which is a useful property of
CX.

Claim 5.  Because C, not CX, is what we actually have, and because of what I
said in Claim 1, a useful feature of C compilers and/or checkers (lint) is the
ability to produce a warning if (a) a `break' keyword denoting a break-switch
operation appears anywhere other than at the end of a case block, or (b) a
(reachable) fall-through operation occurs at the end of a case block.

Claim 6.  In the case of lint, at least, such warnings should be enabled by
default.  There should be lintpragmas (e.g. /*SWITCH*/, /*FALLTHROUGH*/) that
can selectively disable them.

Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint

  reply	other threads:[~1990-02-26 22:02 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5432@crdgw1.crd.ge.com) <8103@hubcap.clemson.edu) <10811@june.cs.washington.edu) <806@enea.se>
1990-02-26 18:48 ` problems/risks due to programming language What`s in a name?
1990-02-26 22:02   ` Karl Heuer [this message]
1990-03-02 10:57   ` Erland Sommarskog
1990-02-28 18:57 problems/risks due to programming language, stories requested Paul Snively
1990-03-02 19:19 ` David F. Carlson
1990-03-03  2:10   ` problems/risks due to programming language Karl Heuer
  -- strict thread matches above, loose matches on Subject: below --
1990-02-24 19:39 Erland Sommarskog
     [not found] <10811@june.cs.washington.edu% <8126@hubcap.clemson.edu% <10838@june.cs.washington.edu>
1990-02-23 18:55 ` B. S. Oplinger
1990-02-23  6:46 Scott MacHaffie
1990-02-21 16:49 problems/risks due to programming language, stories requested Richard A Hammond
1990-02-21 20:15 ` problems/risks due to programming language William Thomas Wolfe, 2847 
1990-02-21 22:49   ` Richard A Hammond
1990-02-21 23:14   ` John F Nixon
1990-02-22  5:39   ` Scott MacHaffie
1990-02-22 20:13     ` William Thomas Wolfe, 2847 
1990-02-23 17:32       ` Richard A Hammond
1990-02-25 20:23         ` David Kassover
1990-02-22 20:48     ` Jeff Lawhorn
1990-02-23  2:00     ` Douglas Miller
1990-02-22 16:05       ` Dan L. Pierson
1990-02-22 20:28         ` David Kassover
1990-02-24 19:52         ` Erland Sommarskog
1990-02-23 17:45       ` Mike Harrison
1990-02-27  2:02         ` Douglas Miller
1990-02-22 18:28   ` Mike Percy
1990-02-23  2:09   ` Douglas Miller
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox