[comp.lang.pascal] problems/risks due to programming language, stories requested

gb@cs.purdue.EDU (Gerald Baumgartner) (02/21/90)

For a research project I am collecting information about the risk of
choosing the wrong programming language. In particular I am looking
for problems that could have been avoided if another (a better)
programming language would have been used.

I know of these three such stories:

     1.	There is the famous story that a Mariner probe got lost
	because of the Fortran statement `DO 3 I = 1.3' (1.3 instead
	of 1,3) (see Peter Neumann: A Few Old War Stories Reappear.
	ACM SIGSOFT 11(5), Oct. 1986, pp. 16-18). It is a nice story
	but, as far as I know, NASA used Jovial at that time and not
	Fortran.

     2. One of the security holes the Internet Worm took advantage of
	was in fingerd (the finger deamon). The deamon uses the gets
	routine for input. This routine, written in C, reads input
	without checking for bounds on the buffer involved. By
	overrunning the buffer, the worm rewrote the stack frame (see
	Eugene H. Spafford: Crisis and Aftermath. Communications of
	the ACM 32(6), June 1989).

	There would be no security hole in the finger daemon if a
	programming language would have been used for the I/O
	routines, where the compiler takes care of boundary checks for
	arrays. Pascal doesn't work since variable length strings are
	needed, but Ada would be fine. A language a la ML, where these
	checks are done at compile time, would be even better.

     3. The AT&T breakdown a month ago was caused by a break statement
	in C. See the following mail (multiple forwarding headers deleted):

Subject: AT&T software problem
Subject: Cautionary note on C programming...AT&T learns from experience
>From: kent@wsl.dec.com
Subj:	I've always thought C looked like line noise.
Subj:	the bug
Subj:	AT&T's bug, for you C users out there...
Subj:	I C what they mean!
Subj:	"c" considered dangerous to telephones
Subj:	Be careful from where you break! (else no long distance calls will make it thru...)
Subj:	C switch breaks AT&T switches!
Subj:	your "c users" list might appreciate this....


I received the following on AT&T's famous bug (and have deleted multiple 
forwarding headers):

| | Subject: AT&T Bug
| | Date: Fri Jan 19 12:18:33 1990
| | 
| | This is the bug that cause the AT&T breakdown
| | the other day (no, it wasn't an MCI virus):
| | 
| | In the switching software (written in C), there was a long
| | "do . . . while" construct, which contained
| |    a "switch" statement, which contained 
| |       an "if" clause, which contained a
| |          "break," which was intended for
| |       the "if" clause, but instead broke from
| |    the "switch" statement.
| | 

	Again it looks like this bug wouldn't have occurred in another
	programming language.

You C what I mean? Do you know other stories like these, if possible
with references? I don't want to praise Ada or pick at C and Fortran;
I am looking for any story where a proveably inappropriate/insecure
programming language has been used.


Gerald Baumgartner   gb@cs.purdue.edu   ...!{decwrl,gatech,ucbvax}!purdue!gb

msb@sq.sq.com (Mark Brader) (02/24/90)

Gerald Baumgartner (gb@cs.purdue.EDU) writes in many groups:
> There is the famous story that a Mariner probe got lost
> because of the Fortran statement `DO 3 I = 1.3' (1.3 instead
> of 1,3) ... It is a nice story but, as far as I know, NASA used
> Jovial at that time and not Fortran.

Just for the record, the above was definitively shown to be fictional
according to authoritative references given in comp.risks (= Risks Digest),
issue 9.75 (I hear), not too many months ago.  There is at least one
textbook that states it as truth; this is wrong.  The actual reason for
the loss of Mariner I was an error in code used in recovering from a
hardware failure; the code had been based on handwritten equations, and
in transcribing one of these, an overbar was deleted from one letter.

A story which may have been the true origin of the "DO statement myth"
was posted fairly recently in alt.folklore.computers; the article
cited a program at NASA that did enter production use with a dot-for-comma
bug in a DO statement, but it wasn't a spacecraft flight control program.
(I didn't save the details and would be happy to see them again.)

Followups directed to alt.folklore.computers.

-- 
Mark Brader			"I'm not going to post a revision: even USENET
utzoo!sq!msb, msb@sq.com	 readers can divide by 100."	-- Brian Reid

This article is in the public domain.

bill@ssd.harris.com (Bill Leonard) (02/28/90)

In article <9790@medusa.cs.purdue.edu> gb@cs.purdue.EDU (Gerald Baumgartner) writes:

   I received the following on AT&T's famous bug (and have deleted multiple 
   forwarding headers):

   | | Subject: AT&T Bug
   | | Date: Fri Jan 19 12:18:33 1990
   | | 
   | | This is the bug that cause the AT&T breakdown
   | | the other day (no, it wasn't an MCI virus):
   | | 
   | | In the switching software (written in C), there was a long
   | | "do . . . while" construct, which contained
   | |    a "switch" statement, which contained 
   | |       an "if" clause, which contained a
   | |          "break," which was intended for
   | |       the "if" clause, but instead broke from
   | |    the "switch" statement.
   | | 

           Again it looks like this bug wouldn't have occurred in another
           programming language.

I can't resist saying that this last statement seems to me to be utter
nonsense.  What programming language (read, compiler) can read the
programmer's mind and tell what he meant?  The use of the "break" statement
was a logic error (actually, it sounds like it was a lack of knowledge of
the language, since "break" does not apply to "if").  I can't imagine a
programming language that could discern this type of error.  [If I use
WHILE instead of IF, for instance, I can expect some things to work and
some not.  Yet I seriously doubt any compiler could possibly detect this
error.]

I certainly think programmers often choose an inappropriate language, but I
shy away from anecdotal stories like these because they seem (to me) to
spread a lot of misinformation.  Unless you implement a project in multiple
languages, it is nothing more than a guess to say what would have happened
if the project had been implemented in some other language.  Perhaps you
would have discovered an even more serious flaw in that language, or you
might simply find it was no better or worse than the one you chose, just
different.

Most of the stories I have heard along these lines all struck me as missing
the point: how well was the program tested?  Were there code reviews?
Design reviews?  All of these techniques are proven to reduce errors.  Most
of the errors in these stories (e.g., the infamous dot-versus-comma one)
should have been found with even rudimentary testing.

Use of an inappropriate language is no excuse for abandoning other techniques
of good software engineering.
--
Bill Leonard
Harris Computer Systems Division
2101 W. Cypress Creek Road
Fort Lauderdale, FL  33309
bill@ssd.csd.harris.com or hcx1!bill@uunet.uu.net

chewy@apple.com (Paul Snively) (03/01/90)

In article <BILL.90Feb27143004@hcx2.ssd.harris.com> bill@ssd.harris.com 
(Bill Leonard) writes:
> In article <9790@medusa.cs.purdue.edu> gb@cs.purdue.EDU (Gerald 
Baumgartner) writes:
>            Again it looks like this bug wouldn't have occurred in another
>            programming language.
> 
> I can't resist saying that this last statement seems to me to be utter
> nonsense.  What programming language (read, compiler) can read the
> programmer's mind and tell what he meant?  The use of the "break" 
statement
> was a logic error (actually, it sounds like it was a lack of knowledge of
> the language, since "break" does not apply to "if").  I can't imagine a
> programming language that could discern this type of error.  [If I use
> WHILE instead of IF, for instance, I can expect some things to work and
> some not.  Yet I seriously doubt any compiler could possibly detect this
> error.]
> 
> I certainly think programmers often choose an inappropriate language, 
but I
> shy away from anecdotal stories like these because they seem (to me) to
> spread a lot of misinformation.  Unless you implement a project in 
multiple
> languages, it is nothing more than a guess to say what would have 
happened
> if the project had been implemented in some other language.  Perhaps you
> would have discovered an even more serious flaw in that language, or you
> might simply find it was no better or worse than the one you chose, just
> different.
> 
> Most of the stories I have heard along these lines all struck me as 
missing
> the point: how well was the program tested?  Were there code reviews?
> Design reviews?  All of these techniques are proven to reduce errors.  
Most
> of the errors in these stories (e.g., the infamous dot-versus-comma one)
> should have been found with even rudimentary testing.
> 
> Use of an inappropriate language is no excuse for abandoning other 
techniques
> of good software engineering.

I don't think that anyone's claiming that it is an excuse; I believe the 
point was that some languages applied to some tasks lend themselves to 
error more than another language applied to the same task.  If you wish to 
interpret the above story as a rather pointed jab at the C programming 
language, and object to C being treated that way, that's fine, but please 
just say so.

For what it's worth, my personal opinion is that C lends itself to 
precisely the kinds of errors noted above--when does break work and when 
doesn't it, and why in God's name do you need it in switch statements in 
the first place, etc.  I believe that it's C's historical looseness that 
is simultaneously its greatest weakness, when it leads to errors like 
this, and its greatest strength--C doesn't restrict you; C is mean and 
lean; C is close to the hardware; real programmers use C; even, God help 
us, C is the only language you need!  We all know C programmers whose 
machismo is thus huffed and puffed up (another of my personal opinions is 
that the per capita arrogance of C programmers far outweighs the per 
capita arrogance of any other language-aficionado group).

Now to get back to the important point: what language would have been 
better for the task in question?

Well, I hate to say it, but it's extremely unlikely that such an error 
would have been made in Pascal, since Pascal doesn't require you to 
explicitly break from case...of constructs.

Before the flames start, let me just add: no, I don't necessarily prefer Pascal over C for all tasks.  I generally attempt to choose the right tool for the job, rather than falling into the "when all you have is a hammer, everything looks like a nail" trap.

Standard Disclaimer.

jk0@image.soe.clarkson.edu (Jason Coughlin) (03/01/90)

From article <6960@internal.Apple.COM>, by chewy@apple.com (Paul Snively):
> For what it's worth, my personal opinion is that C lends itself to 
> precisely the kinds of errors noted above--when does break work and when 
> doesn't it, and why in God's name do you need it in switch statements in 
> the first place, etc.

	Gee, if you read the language defn you'd know exactly when break
applies and when break doesn't.  It seems to me that it is the
programmer's responsibility to know the language in which he is going to
implement said project -- it's not necessarily the language's responsibility
to know the programmer didn't read the defn.

> Well, I hate to say it, but it's extremely unlikely that such an error 
> would have been made in Pascal, since Pascal doesn't require you to 
> explicitly break from case...of constructs.

	And without knowing the project, you have no business making the
assertion that Pascal was better than C [especially on a Unix box] or
that C was better than Pascal [especially on a VMS box].
-- 
Jason Coughlin ( jk0@sun.soe.clarkson.edu , jk0@clutx )
"Every jumbled pile of person has a thinking part that wonders what the
part that isn't thinking isn't thinking of." - They Might Be Giants

jeff@aiai.ed.ac.uk (Jeff Dalton) (03/01/90)

In article <6960@internal.Apple.COM> chewy@apple.com (Paul Snively) writes:
 >machismo is thus huffed and puffed up (another of my personal opinions is 
 >that the per capita arrogance of C programmers far outweighs the per 
 >capita arrogance of any other language-aficionado group).

Except for Pascal programmers.  Even Wirth has moved on by now.

barmar@think.com (Barry Margolin) (03/02/90)

In article <1990Feb28.213543.21748@sun.soe.clarkson.edu> jk0@image.soe.clarkson.edu (Jason Coughlin) writes:
>	Gee, if you read the language defn you'd know exactly when break
>applies and when break doesn't.  It seems to me that it is the
>programmer's responsibility to know the language in which he is going to
>implement said project -- it's not necessarily the language's responsibility
>to know the programmer didn't read the defn.

What would you say if a car designer used a similar excuse: Gee, if you'd
read the owner's manual for the 6000SUX you'd know that you have to turn
the radio off before stepping on the brake pedal.  It seems to me that it
is the driver's responsibility to know the car he's driving -- it's not
necessarily the manufacturer's responsibility to know that the driver
didn't read the manual.

Yes, it's the resposibility of the programmer to know the language.  But
it's the responsibility of language designers to design languages
reasonably.  If programmer-friendliness weren't an issue we'd still be
programming in machine language.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

lins@Apple.COM (Chuck Lins) (03/02/90)

In article <1883@skye.ed.ac.uk> jeff@aiai.UUCP (Jeff Dalton) writes:
>In article <6960@internal.Apple.COM> chewy@apple.com (Paul Snively) writes:
> >machismo is thus huffed and puffed up (another of my personal opinions is 
> >that the per capita arrogance of C programmers far outweighs the per 
> >capita arrogance of any other language-aficionado group).
>
>Except for Pascal programmers.  Even Wirth has moved on by now.

                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Yup. Even beyond Modula-2 to Oberon. And several colleagues at ETHZ have
enhance Oberon with object-oriented extensions.

-- 
Chuck Lins               | "Exit left to funway."
Apple Computer, Inc.     | Internet: lins@apple.com
20525 Mariani Avenue     | AppleLink: LINS
Mail Stop 41-K           | 
Cupertino, CA 95014      | "Self-proclaimed Object Oberon Evangelist"
The intersection of Apple's ideas and my ideas yields the empty set.

dave@micropen (David F. Carlson) (03/03/90)

In article <6960@internal.Apple.COM>, chewy@apple.com (Paul Snively) writes:
> 
> 
> For what it's worth, my personal opinion is that C lends itself to 
> precisely the kinds of errors noted above--when does break work and when 
> doesn't it, and why in God's name do you need it in switch statements in 
> the first place, etc.

What break does is *very* well defined and is no more prone to misinterpretation
that any other non-linear control flow statement in any other PL.

From K&R2 p 244:

	A9.5: iteration statement is (for, while, do)...

	A break statement may appear only in an iteration statement or a switch 
	statement; control passes to the statement following the terminated
	statement.

A multi-case switch is very handy in many situations to reduce identical
treatments for similar cases.  That you ask the question of the usefulness
of break-per-case/multiple-cases implies that you haven't sufficient experience
with the construct to judge its merits/weaknesses.

Dijkstra notes that no programming language can prevent a poor programmer from
creating bad programs.

-- 
David F. Carlson, Micropen, Inc.
micropen!dave@ee.rochester.edu

"The faster I go, the behinder I get." --Lewis Carroll

billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu (William Thomas Wolfe, 2847 ) (03/03/90)

From dave@micropen (David F. Carlson):
>> For what it's worth, my personal opinion is that C lends itself to 
>> precisely the kinds of errors noted above--when does break work and when 
>> doesn't it, and why in God's name do you need it in switch statements in 
>> the first place, etc.
> 
> A multi-case switch is very handy in many situations to reduce identical
> treatments for similar cases.  

   So is a multi-alternative case, as provided by Ada:

      case Foo is
         when 1 | 3 | 5 =>
            statement1;
         when 2 | 4 | 6 =>
            statement2;
         when others =>
            statement3;
      end case;

   The difference is that Ada takes care of exiting the case statement
   for you, whereas C requires (unsafely) that you use a break to avoid 
   being sucked into the code associated with subsequent cases.  


   Bill Wolfe, wtwolfe@hubcap.clemson.edu

bouma@cs.purdue.EDU (William J. Bouma) (03/03/90)

In article <6960@internal.Apple.COM> chewy@apple.com (Paul Snively) writes:
>We all know C programmers whose 
>machismo is thus huffed and puffed up (another of my personal opinions is 
>that the per capita arrogance of C programmers far outweighs the per 
>capita arrogance of any other language-aficionado group).


   Oh, really! I can tell you have never met any FORTH programmers.

 
>Well, I hate to say it, but it's extremely unlikely that such an error 
>would have been made in Pascal, since Pascal doesn't require you to 
>explicitly break from case...of constructs.


   Well isn't that special! The way I see it, C gives you the flexibility
   to not break if you don't want to, where PASCAL restricts you to break.


>Before the flames start,

   Too late!

> let me just add: no, I don't necessarily prefer Pascal over C for all tasks.


   The only place I can see to prefer PASCAL over C is a beginner programming
   class. Isn't PASCAL usually thrown out along with the diapers?
   
-- 
Bill <bouma@cs.purdue.edu>  |  And don't forget my dog... "Astronomy" -- BOC

jlg@lambda.UUCP (Jim Giles) (03/03/90)

From article <1004@micropen>, by dave@micropen (David F. Carlson):
> [... explicit breaks in the C switch construct ...]
> Dijkstra notes that no programming language can prevent a poor programmer from
> creating bad programs.

He also notes that the choice of programming language can have a strong
effect on the quality of the resulting code.  (His indictment of PL/I
as being similar to flying a widebodied jet with all the windows taped
over and no labels on the thousands of controls was quite apropos.)
This effect of the language choice is mainly psychological - and it
CAN be overcome (which is the main thrust of many of Dijkstra's works).
But, be honest, how many programmers do you know who _really_ construct
their programs abstractly _before_ even selecting their implementation
language?  This is the proper way (a' la Dijkstra) to make sure the
you aren't negatively impacted by the language - you select the proper
language for the job at hand - you don't mangle the job to fit the
language.

Dijkstra's statement, while true, should not be used to excuse poorly
designed language features (as you are trying to do).  A better design
for C would have been _not_ to require breaks after each case and to
provide some other syntax for the representation of multiple choices
on the same case.  It's easy to see these kinds of design errors
in retrospect (C _is_ nearly 20 years old you know).

J. Giles

manis@cs.ubc.ca (Vincent Manis) (03/03/90)

I might note that B's syntax, and hence C's syntax, was a definite
*dis*improvement [sic] over that of its predecessor, BCPL. I would in
fact post an article saying exactly that, except for the fact that this
entire thread most certainly belongs somewhere, but not in
comp.lang.scheme.  Would you please edit the Newsgroups: line in further
articles on this subject?

--
\    Vincent Manis <manis@cs.ubc.ca>      "There is no law that vulgarity and
 \   Department of Computer Science      literary excellence cannot coexist."
 /\  University of British Columbia                        -- A. Trevor Hodge
/  \ Vancouver, BC, Canada V6T 1W5 (604) 228-2394

jbaker@gmu90x.gmu.edu (jbaker) (03/06/90)

In article <8218@hubcap.clemson.edu> Bill Wolf writes:
>From dave@micropen (David F. Carlson):
>>> For what it's worth, my personal opinion is that C lends itself to 
>>> precisely the kinds of errors noted above--when does break work and when 
>>> doesn't it, and why in God's name do you need it in switch statements in 
>>> the first place, etc.
>> 
>> A multi-case switch is very handy in many situations to reduce identical
>> treatments for similar cases.  

But the real usefulness of requiring break in a switch statement is for
SIMILAR treatments of similar cases, for example you may require a
few assignments in one case before a more complicated computation which
must be performed for several of the cases.

This could be done in other languages using conditionals or multiple case
statements, but it's not quite as nice.

Bill Wolf writes:
>   So is a multi-alternative case, as provided by Ada:
>
>      case Foo is
>         when 1 | 3 | 5 =>
>            statement1;
>         when 2 | 4 | 6 =>
>            statement2;
>         when others =>
>            statement3;
>      end case;
>
>   The difference is that Ada takes care of exiting the case statement
>   for you, whereas C requires (unsafely) that you use a break to avoid 
>   being sucked into the code associated with subsequent cases.  
>
But this is just one example of the design philosophy of C: flexibility;
if the machine will let you do it (or naturally WANTS to do it), let the
programmer do it the same way.  Other examples of such flexibilty are the
lack of type-checking, as well as allowing assignments just about anywhere.

Some languages, such as Pascal, have more limitations (or less extentions)
in their constructs.  This usually is perfectly adequate, but for someone
who writes code while thinking about how the machine will execute that 
code, as I do, flexibility can be useful; a small amount of speed-up, and more
compact code can be the result. 

However, this capability has a trade-off; flexibility for follow-ability.
Humans do not think like computers.  We can not precisely process syntax.
When code becomes too involved, it can become very difficult to follow for
even the author.  What could be a straight-foward program may now be a twisted
mess.  It becomes easy to overlook bugs that would be obvious in other
languages.  This is why C programmers rely heavily on a debugger.
What one calls "safety" in a language, then, is just how well humans can
follow a construct, without regard for its usefulness.  C is not "safe,"
but while being quite simple and relatively low-level, it contains many
flexible constucts.

Sometimes, though, flexibility is present in other languages in a more
"safe" fashion.  For example, type conversion is available in Modula-2
IF it is explicitly done in the code.  In order to use a pointer as a
integer, for example, one might use: INTEGER(ch^).  This flags the compiler
that "we meant to do that" and warns humans that something tricky is going on.

But C can be delightful to use, if you are very careful to write clear code.


John Baker
jbaker@gmuvax.gmu.edu

Now about deciphering all those }++|#{ symbols....

lou@atanasoff.rutgers.edu (Lou Steinberg) (03/08/90)

In article <2596@gmu90x.gmu.edu> jbaker@gmu90x.gmu.edu (jbaker) writes:

> In article <8218@hubcap.clemson.edu> Bill Wolf writes:
> >From dave@micropen (David F. Carlson):
> >> A multi-case switch is very handy in many situations to reduce identical
> >> treatments for similar cases.  
> 
> But the real usefulness of requiring break in a switch statement is for
> SIMILAR treatments of similar cases, for example you may require a
> few assignments in one case before a more complicated computation which
> must be performed for several of the cases.

ARGHHH!!  That is what subroutines (and macros) are for - to handle
common code.  And if your language makes them too expensive, either in
terms of run time or in terms of programmer effort, then THAT is an
even worse problem with the language than the problems with break.
-- 
					Lou Steinberg

uucp:   {pretty much any major site}!rutgers!aramis.rutgers.edu!lou 
arpa:   lou@cs.rutgers.edu

ciardo@software.org (Gianfranco Ciardo) (03/09/90)

In article <Mar.8.10.19.49.1990.3812@atanasoff.rutgers.edu> lou@atanasoff.rutgers.edu (Lou Steinberg) writes:
> > >> A multi-case switch is very handy in many situations to reduce identical
> > >> treatments for similar cases.  
> ARGHHH!!  That is what subroutines (and macros) are for - to handle
> common code.  And if your language makes them too expensive, either in
> terms of run time or in terms of programmer effort, then THAT is an
> even worse problem with the language than the problems with break.

I think you miss completely the point.
Using subroutines is not going to help you make the code shorter, more compact,
or less repetitious (which is not) in a case like this:

          switch (what_to_do) {
                    case FIVE_THINGS:
                            <statementA>;
                    case FOUR_THINGS:
                            <statementB>;
                    case THREE_THINGS:
                            <statementC>;
                    case TWO_THINGS:
                            <statementD>;
                    case ONE_THING:
                            <statementE>;
                    case NOTHING:
                            break;
          }

kassover@jupiter.crd.ge.com (David Kassover) (03/10/90)

In article <672@software.software.org> ciardo@software.org (Gianfranco Ciardo) writes:
...
>
>I think you miss completely the point.
>Using subroutines is not going to help you make the code shorter, more compact,
>or less repetitious (which is not) in a case like this:
>
>          switch (what_to_do) {
>                    case FIVE_THINGS:
>                            <statementA>;
>                    case FOUR_THINGS:
>                            <statementB>;
>                    case THREE_THINGS:
>                            <statementC>;
>                    case TWO_THINGS:
>                            <statementD>;
>                    case ONE_THING:
>                            <statementE>;
>                    case NOTHING:
>                            break;
>          }

No, but without fall through, you would write such a thing upside
down.  Or do something else.
 
A couple of weeks ago I mentioned a (please bear with me) Fortran
preprocessor called FLEX, which provided 4 kinds of case
statement, two with fall through, two without.
 
One instance:  A particular programmer, whom I have worked with
for about 10 years, rarely, if ever, used the FLEX
cases-with-fallthrough.
 
Now that he has learned C (and not recently, bTW), it seems like
he goes out of his way to *USE* fall-through.


I wonder why it is so difficult for language designers to provide
more than one way to do things?

gat@robotics.Jpl.Nasa.Gov (Erann Gat) (03/10/90)

In article <672@software.software.org>, ciardo@software.org (Gianfranco Ciardo) writes:
> Using subroutines is not going to help you make the code shorter, more compact,
> or less repetitious (which is not) in a case like this:
> 
>           switch (what_to_do) {
>                     case FIVE_THINGS:
>                             <statementA>;
>                     case FOUR_THINGS:
>                             <statementB>;
			[etc.]
>                     case ONE_THING:
>                             <statementE>;
>                     case NOTHING:
>                             break;
>           }

No, but writing the code like this will:

	if (what_to_do >= ONE_THING) <statementE>;
	if (what_to_do >= TWO_THINGS) <statementD>;
	if (what_to_do >= THREE_THINGS) <statementC>;
	if (what_to_do >= TWO_THINGS) <statementB>;
	if (what_to_do >= ONE_THING) <statementA>;

If you wish to quibble over my use of inequalities, replace them with
a disjunction of equalities.

Erann Gat                  gat@robotics.jpl.nasa.gov

sanders@sanders.austin.ibm.com (Tony Sanders) (03/10/90)

In article <8218@hubcap.clemson.edu> billwolf%hazel.cs.clemson.edu@hubcap.clemson.edu writes:
>   So is a multi-alternative case, as provided by Ada:
How do you do this in ADA?

    switch(n) {
      case 0:
	count++;
      case 1:
	ocount++;
      case 2:
	printf("%d %d\n",count,ocount);
	break;
      default:
	printf("unknown n\n");
	break;
    }

See how I left out the breaks on purpose.

In ADA you wouldn't be able to do this without duplicating either the
case-expression (they aren't always simple numbers) or the statements.

-- sanders                The 11th commandment: "Thou shalt use lint"
For every message of the day, a new improved message will arise to overcome it.
Reply-To:  cs.utexas.edu!ibmaus!auschs!sanders.austin.ibm.com!sanders

amull@Morgan.COM (Andrew P. Mullhaupt) (03/11/90)

> or less repetitious (which is not) in a case like this:
> 
>           switch (what_to_do) {
>                     case FIVE_THINGS:
...

This stuff doesn't belong in comp.lang.pascal. It goes in comp.lang.c,
right(?). The fistfight over bill wolfe's complaints about C should
stay in comp.lang.c. If anyone wants to complain about Pascal, then
put it in here. 

BTW - fall through and the 'double duty' break keyword are
definitely examples of C flaws.  If you must, flame me, but in 
comp.lang.c, (OK?)

Later,
Andrew Mullhaupt

peter@ficc.uu.net (Peter da Silva) (03/12/90)

> This stuff doesn't belong in comp.lang.pascal. It goes in comp.lang.c,
> right(?).

No, it doesn't belong in comp.lang.c either. Language lawyers should hold
their court in comp.lang.misc or alt.religion.computers. this thread may have
some slight relevence to comp.software-eng. It doesn't belong in any of
comp.lang.{c,ada}... and even less in comp.lang.{lisp,modula2,pascal}.
-- 
 _--_|\  `-_-' Peter da Silva. +1 713 274 5180. <peter@ficc.uu.net>.
/      \  'U`
\_.--._/
      v

jclark@SRC.Honeywell.COM (Jeff Clark) (03/13/90)

In article <775@s5.Morgan.COM> amull@Morgan.COM (Andrew P. Mullhaupt) writes:

   This stuff doesn't belong in comp.lang.pascal. It goes in comp.lang.c,

Actually, I don't think it belongs in any of these groups.   This "discussion"
seems to have no end and no reasonable resolution since the antagonists
arguments are based on personal opinions, preferences, and emotions.  I've not
seen anyone quote studies of the influence of "human factors" in programming
language design nor has any one proposed such a study as a useful outcome of
this recent flame war (although I must admit I'm wearing out the 'n' key on my
workstation).

comp.lang.religious-wars anyone?

Jeff Clark	Honeywell Systems and Research Center	Minneapolis, MN
inet: jclark@src.honeywell.com		tel: 612-782-7347
uucp: jclark@srcsip.UUCP		fax: 612-782-7438
DISCLAIMER: If you think I speak for my employer, you need serious help ...

lindsay@comp.vuw.ac.nz (Lindsay Groves) (03/14/90)

In article <1004@micropen>, dave@micropen (David F. Carlson) writes:
> What break does is *very* well defined and is no more prone to
misinterpretation
> that any other non-linear control flow statement in any other PL.

A number of people in this discussion (which I haven't reached the end of yet!)
have said things like this, and appear to be suggesting that because something
is well defined there is no excuse for anyone misusing it.  I disagree
with that
and also with the second part of this statement.  There are languages in which
any kind of exit has to explicitly name the construct to be exitted -- so there
is no possiblity of consfusion about which construct the exit/break/etc.
applies
to.

> A multi-case switch is very handy in many situations to reduce identical
> treatments for similar cases.  That you ask the question of the usefulness
> of break-per-case/multiple-cases implies that you haven't sufficient
experience
> with the construct to judge its merits/weaknesses.
> 
> Dijkstra notes that no programming language can prevent a poor
programmer from
> creating bad programs.

So why aren't we all still using FORTRAN (or some older dialect)?  Why did we
all think that unlabelled CASE statements (as in Algol-W and Burroughs Algol)
were a big improvement over computed GOTOs in FORTRAN (which is basically what
the switch in C is), or that the labelled CASE statement (as in Pascal) was
a big improvement over that?  Maybe the whole of the last 30 years of work in
programming language design has been a dream!!!

Lindsay Groves

jaws@chibacity.austin.ibm.com (03/15/90)

Mr Wolf:

C allows you to combine cases that have portions of similiar code
but may have extra lead in code for a specific case:

	switch var:
	case A:
		/* do stuff only case A needs */

	case B:
		/* do stuff case A and case B need done */
		.
		.
		break;

	/* rest of switch */
	

this construct in impossible to do cleanly in almost every language I have
ever seem, especially ADA.

This kind flexiability is what makes C so powerfull, and dangerous. 
You have know what you are doing to do it.


[ Jeff Wilson :: jaws@chibacity.austin.ibm.com                                ]
[ Consultant from Pencom, Inc. at Human Factors, AWD, IBM Austin.             ]
[My comments are wholly my own and as such take them for what they are worth. ]

vanavermaet@kerber.dec.com (03/16/90)

with standard_disclaimer; use standard_disclaimer;

In article <1819@awdprime.UUCP>, jaws@chibacity.austin.ibm.com writes...
>This kind flexiability is what makes C so powerfull, and dangerous. 
>You have know what you are doing to do it.

I think this is a very sensible remark.

O.K., the semantics are well-defined (as may people have pointed out),
but it still IS dangerous. That (IMHO) is a very important factor (and to me, a
reason not to use C).

Peter Van Avermaet